From 72425125ddc2243274edf6e48012987fb38a8f2a Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Mon, 3 May 2021 11:23:18 +0300 Subject: project.utils: fix the retry decorator --- project/utils.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'project') diff --git a/project/utils.py b/project/utils.py index f40767a..06fff27 100644 --- a/project/utils.py +++ b/project/utils.py @@ -91,17 +91,19 @@ def env(name): return os.environ[name] -def retry(exc_type, timeout=5, retries=3, backoff=2): +def retry(exc_type, timeout=5, tries=3, backoff=2): def wrapper(func): @functools.wraps(func) def func2(*args, **kwargs): current_timeout = timeout - for retry_n in range(retries): + current_try = 0 + while True: try: return func(*args, **kwargs) except exc_type as e: logging.exception(e) - if retry_n < retries: + current_try += 1 + if current_try < tries: logging.error('Retrying after %d seconds', current_timeout) time.sleep(current_timeout) current_timeout *= backoff -- cgit v1.2.3