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
This commit is contained in:
Sorin Sbarnea 2020-09-28 15:34:43 +01:00
parent 40858f3678
commit ac82273984

View File

@ -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