From ac822739841a91f61c0bbb6aad21f44f89ef637d Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Mon, 28 Sep 2020 15:34:43 +0100 Subject: [PATCH] Allow custom retries on gerrit connection Previous code was not allowing use of Gerrit without hardcoded infinite retries inside Gerrit constructor, meaning that wrong credentials would create an endless loop which gerritlib consumer could not prevent. This allows client to specify number of attempts and delay before a failure is returned. Change-Id: I5bd14a14539a2705babb9f9922c800383031c6ac --- gerritlib/gerrit.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/gerritlib/gerrit.py b/gerritlib/gerrit.py index a518bfb..0089bc9 100644 --- a/gerritlib/gerrit.py +++ b/gerritlib/gerrit.py @@ -199,10 +199,16 @@ class GerritWatcher(threading.Thread): class Gerrit(object): log = logging.getLogger("gerrit.Gerrit") - def __init__(self, hostname, username, port=29418, keyfile=None, - keep_alive_interval=0): - self.connection = GerritConnection(username, hostname, port, keyfile, - keep_alive=keep_alive_interval) + def __init__( + self, hostname, username, port=29418, keyfile=None, + keep_alive_interval=0, + connection_attempts=-1, + retry_delay=5): + self.connection = GerritConnection( + username, hostname, port, keyfile, + keep_alive=keep_alive_interval, + connection_attempts=connection_attempts, + retry_delay=retry_delay) self.client = None self.watcher_thread = None self.event_queue = None