Skip to content

Commit

Permalink
handle the secondary rate limit (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
sgandhi1311 authored May 15, 2023
1 parent 7013274 commit 371e962
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# Changelog

# 2.0.3
* Handles the secondary rate limit - `Retry-After` [#191](https://github.com/singer-io/tap-github/pull/191)

# 2.0.2
* Make the tap sleep for `X-RateLimit-Reset` + `2` seconds, whenever the API rate limit is hit [#187](https://github.com/singer-io/tap-github/pull/187)
* Make the tap sleep for `X-RateLimit-Reset` + `2` seconds, whenever the API rate limit is hit [#190](https://github.com/singer-io/tap-github/pull/190)

# 2.0.1
* Allow `commits` stream sync to continue when we hit an empty repo [#187](https://github.com/singer-io/tap-github/pull/187)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from setuptools import setup, find_packages

setup(name='tap-github',
version='2.0.2',
version='2.0.3',
description='Singer.io tap for extracting data from the GitHub API',
author='Stitch',
url='http://singer.io',
Expand Down
7 changes: 7 additions & 0 deletions tap_github/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,13 @@ def rate_throttling(response):
"""
For rate limit errors, get the remaining time before retrying and calculate the time to sleep before making a new request.
"""
if "Retry-After" in response.headers:
# handles the secondary rate limit
seconds_to_sleep = int(response.headers['Retry-After'])
LOGGER.info("API rate limit exceeded. Tap will retry the data collection after %s seconds.", seconds_to_sleep)
time.sleep(seconds_to_sleep)
#returns True if tap sleeps
return True
if 'X-RateLimit-Remaining' in response.headers:
if int(response.headers['X-RateLimit-Remaining']) == 0:
seconds_to_sleep = calculate_seconds(int(response.headers['X-RateLimit-Reset']))
Expand Down

0 comments on commit 371e962

Please sign in to comment.