Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

[Idea] Sleep until rate limit updates and try again #1644

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions app/models/github_model.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,14 @@ def github_response(client, id)
# Returns a Sawyer::Resource or raises and error.
def github_client_request(client, id, **options)
GitHub::Errors.with_error_handling { client.send(github_type, id, options) }
rescue GitHub::TooManyRequests
retries ||= 0
if retries < 1
retries +=1

Choose a reason for hiding this comment

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

Layout/SpaceAroundOperators: Surrounding space missing for operator +=.

sleep client.rate_limit.resets_in + 1
retry
end
nil
rescue GitHub::Error
nil
end
Expand All @@ -132,6 +140,14 @@ def github_classroom_request(id, **options)
GitHub::Errors.with_error_handling do
GitHubClassroom.github_client.send(github_type, id, options)
end
rescue GitHub::TooManyRequests
retries ||= 0
if retries < 1
retries +=1

Choose a reason for hiding this comment

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

Layout/SpaceAroundOperators: Surrounding space missing for operator +=.

sleep client.rate_limit.resets_in + 1
retry
end
nil
rescue GitHub::Error
nil
end
Expand Down