From 371e962a4b0eec7be6eb7d92c48cc87c245a6277 Mon Sep 17 00:00:00 2001 From: Sourabh Gandhi <105213416+sgandhi1311@users.noreply.github.com> Date: Tue, 16 May 2023 00:03:49 +0530 Subject: [PATCH] handle the secondary rate limit (#191) --- CHANGELOG.md | 5 ++++- setup.py | 2 +- tap_github/client.py | 7 +++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 040bfa3d..4182f874 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/setup.py b/setup.py index 6d9ba88d..151dbf9c 100644 --- a/setup.py +++ b/setup.py @@ -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', diff --git a/tap_github/client.py b/tap_github/client.py index fe6b3de4..c7d7f880 100644 --- a/tap_github/client.py +++ b/tap_github/client.py @@ -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']))