Skip to content

Commit

Permalink
Add exponential sleep increase
Browse files Browse the repository at this point in the history
  • Loading branch information
lawang24 committed May 2, 2024
1 parent bdfd787 commit f222ed7
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions issue_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,24 @@ def search_issues(
List[github3.search.IssueSearchResult]: A list of issues that match the search query.
"""

# Rate Limit Handling: API only allows 30 requests per minute
def wait_for_api_refresh(iterator: github3.structs.SearchIterator):
# Rate Limit Handling: API only allows 30 requests per minute
max_retries = 5
retry_count = 0
sleep_time = 70

while iterator.ratelimit_remaining < 5:
print("Github API Rate Limit Low, waiting 1 minute to refresh")
sleep(65)
if retry_count >= max_retries:
raise RuntimeError("Exceeded maximum retries for API rate limit")

print(
f"GitHub API Rate Limit Low, waiting {sleep_time} seconds to refresh."
)
sleep(sleep_time)

# Exponentially increase the sleep time for the next retry
sleep_time *= 2
retry_count += 1

issues_per_page = 100

Expand Down

0 comments on commit f222ed7

Please sign in to comment.