Skip to content

Commit

Permalink
Handle Additional GitHub secondary rate limit failure (#68)
Browse files Browse the repository at this point in the history
We previously handled secondary rate limit errors, however, it turns
out that we aren't getting the exception type that we were seeing then
for all secondary rate limits.

This PR updates to handle the generic "GitHubException" that PyGitHub
uses. If we get the more generic error and it contains a secondary
rate limit message from GitHub, we will handle with our usual "wait
and try again" strategy.
  • Loading branch information
SeanTAllen authored Oct 16, 2024
1 parent b13f9b4 commit 28b5d83
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .release-notes/68.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## Handle Additional GitHub secondary rate limit failure

In our previous version, we added support for retrying when a secondary rate limit failure occurred. However, since that time, we have seen secondary rate limit failures that are not handled by the previous fix. This update adds a retry for the one time we know that the limit can be triggered. If the rate limit is triggered, the bot will wait for 30 seconds before trying again. If it encounters 5 failures, it will give up and quit.
15 changes: 15 additions & 0 deletions entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from git.exc import GitCommandError
from github import Github
from github.GithubException import RateLimitExceededException
from github.GithubException import GithubException

CHANGELOG_LABELS = ['changelog - added',
'changelog - changed',
Expand Down Expand Up @@ -67,6 +68,20 @@
else:
print(ERROR + "Search failed again. Giving up." + ENDC)
raise
except GithubException as e:
if "You have exceeded a secondary rate limit" in e.data['message']:
search_failures += 1
if search_failures <= 5:
print(NOTICE
+ "Search failed due to secondary rate limit exceeded. "
+ "Sleeping and trying again."
+ ENDC)
time.sleep(30)
else:
print(ERROR + "Search failed again. Giving up." + ENDC)
raise
else:
raise

repo = github.get_repo(repo_name)
pull_request = repo.get_pull(pr_id)
Expand Down

0 comments on commit 28b5d83

Please sign in to comment.