Skip to content

Commit

Permalink
Fix retry decorator so it returns the value
Browse files Browse the repository at this point in the history
  • Loading branch information
tomrittervg committed Sep 5, 2024
1 parent 456cf35 commit d9c5b86
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions components/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def decorate(func):

return decorate


# Retry calling a function `times` times, sleeping between each tries, with an exponential backoff
# This is to be used on API calls, that are likely to fail

Expand All @@ -152,15 +153,13 @@ def wrapper_retry(*args, **kwargs):
sleep_duration = sleep_s
while retries_try > 0:
try:
func(*args, **kwargs)
break
return func(*args, **kwargs)
except BaseException as e:
retries_try -= 1
time.sleep(sleep_duration)
sleep_duration *= exp
if retries_try == 0:
raise e

return wrapper_retry

if _func is None:
Expand Down

0 comments on commit d9c5b86

Please sign in to comment.