Skip to content

Commit

Permalink
adjust logic
Browse files Browse the repository at this point in the history
  • Loading branch information
Kukant committed Oct 14, 2024
1 parent 5b597be commit 2fa6f42
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions kbcstorage/retry_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@

MAX_RETRIES = 5
BACKOFF_FACTOR = 1.0
RETRY_STATUS_CODES = {500, 502, 503, 504}


def _get_backoff_time(retry_count):
return BACKOFF_FACTOR * (2 ** retry_count)

def _retry_request(request_func, url, *args, **kwargs):
response = request_func(url, *args, **kwargs)
for retry_count in range(1, MAX_RETRIES):
if response.status_code not in RETRY_STATUS_CODES:
for retry_count in range(MAX_RETRIES - 1):
if response.status_code == 501 or response.status_code < 500:
return response
time.sleep(_get_backoff_time(retry_count))
response = request_func(url, **kwargs)
Expand Down

0 comments on commit 2fa6f42

Please sign in to comment.