retrying
retrying copied to clipboard
How to reset an exponential_sleep configuration, after a successfull_threshold again?
Great lib, which saved me definitive from an ugly hack to make "requests" calls retrying on the status_code :)
def retry_if_result_429(response):
"""Return True if we should retry (in this case when the status_code is 429), False otherwise"""
# DEBUG to see this in action
if response.status_code == 429:
print 'RETRY 429: %s' % response.url
return True
else:
return False
#
# functools partial to the help
# to inject auth parameter in the get/delete/post/put requests
#
retry429_decorator = retry(
retry_on_result=retry_if_result_429,
wait_exponential_multiplier=1000,
wait_exponential_max=10000
)
#1. curry the authentication
#2. decorate it with the retry logic
s.get = retry429_decorator(partial(s.get, auth=credentials))
s.put = retry429_decorator(partial(s.put, auth=credentials))
s.post = retry429_decorator(partial(s.post, auth=credentials))
s.delete = retry429_decorator(partial(s.delete, auth=credentials))
But running a huge test, I have the doubt now, that one of my batches had run into the "wait_exponential_max" and that this will not be reset.
Will the wait_function applied to every subsequent call? Or will the delay happen only when it run into a retry again?
Any idea how to achieve a reset? Resetting the "attempt_number" for example?
thx for any hint or clarification, when the delay happens