From 587949b57ff6a0f934b956b8543386e87892eb10 Mon Sep 17 00:00:00 2001 From: Sourabh Gandhi <105213416+sgandhi1311@users.noreply.github.com> Date: Tue, 16 May 2023 15:55:27 +0530 Subject: [PATCH] Recursively call the function if `Retry-After` has the value greater than 0 (#192) --- CHANGELOG.md | 3 +++ setup.py | 2 +- tap_github/client.py | 9 +++++---- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4182f874..760a29af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +# 2.0.4 + * Recursively call the function if `Retry-After` has the value greater than 0 [#192](https://github.com/singer-io/tap-github/pull/192) + # 2.0.3 * Handles the secondary rate limit - `Retry-After` [#191](https://github.com/singer-io/tap-github/pull/191) diff --git a/setup.py b/setup.py index 151dbf9c..e19b70d8 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from setuptools import setup, find_packages setup(name='tap-github', - version='2.0.3', + version='2.0.4', 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 c7d7f880..9e846282 100644 --- a/tap_github/client.py +++ b/tap_github/client.py @@ -142,10 +142,11 @@ def rate_throttling(response): 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 seconds_to_sleep > 0: + 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']))