Skip to content

Commit

Permalink
Fix secondary throttling issue
Browse files Browse the repository at this point in the history
  • Loading branch information
nir-valtman committed Sep 5, 2022
1 parent d1db42e commit fee93a7
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,10 @@ async def __validate_rate_limit(self, resp):
remaining_requests = int(resp.headers['X-RateLimit-Remaining']) if 'X-RateLimit-Remaining' in resp.headers else 2
if remaining_requests <= 1:
time_to_sleep = (int(resp.headers['X-RateLimit-Reset']) - datetime.timestamp(datetime.now())) + 1
logging.info(f'Sleeping for {time_to_sleep} seconds')
time.sleep(time_to_sleep)
logging.info(f'Primary Throttling: sleeping for {time_to_sleep} seconds')
time.sleep(time_to_sleep)
else:
retry_after = int(resp.headers['Retry-After']) if 'Retry-After' in resp.headers else 0
if retry_after > 0:
logging.info(f'Secondary Throttling: sleeping for {time_to_sleep} seconds')
time.sleep(time_to_sleep)

0 comments on commit fee93a7

Please sign in to comment.