Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Logic to Handle if Key Encounters GitHub API Rate Limit #268

Merged
merged 4 commits into from
Oct 18, 2024

Conversation

IsaacMilarky
Copy link
Collaborator

Add Logic to Handle if Key Encounters GitHub API Rate Limit

Problem

The script doesn't handle the situation where it encounters a GitHub rate limit.

Solution

Check the api response object to see if a rate limit status was encountered. If it was then sleep for the amount of time given by the GitHub response header x-ratelimit-reset.

More information on the GitHub rate limit can be found here: https://docs.github.com/en/rest/using-the-rest-api/rate-limits-for-the-rest-api?apiVersion=2022-11-28

Result

Summary:

  • Add loop to retry when issues are encountered
  • Check response code for rate limit ( 403 and 429 )
  • Extract x-ratelimit-reset from response header if rate limit triggered, this is a timestamp for when the key will be good again. We convert the timestamp into a duration in seconds and then sleep for that many seconds
  • Get local time for when the key will be good again and print to stdout
  • Raise ConnectionError if rate limit still happens after 5 tries

Test Plan

I have tested the script locally

IsaacMilarky and others added 3 commits October 16, 2024 16:41
Signed-off-by: Isaac Milarsky <[email protected]>
… if rate limit can't be slept to fix

Signed-off-by: Isaac Milarsky <[email protected]>
@IsaacMilarky IsaacMilarky added bug Something isn't working enhancement New feature or request labels Oct 16, 2024
@IsaacMilarky IsaacMilarky self-assigned this Oct 16, 2024
Copy link
Contributor

@sachin-panayil sachin-panayil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great way to handle this 🚢

@sachin-panayil sachin-panayil merged commit 5e032ef into dev Oct 18, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants