From 55222656379f2e7e61c83b978d77c177a5451ae7 Mon Sep 17 00:00:00 2001 From: John Britton Date: Thu, 11 Oct 2018 01:39:54 -0400 Subject: [PATCH] sleep until rate limit updates and try again --- app/models/github_model.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/models/github_model.rb b/app/models/github_model.rb index 4e1c6b684d..f8f98779eb 100644 --- a/app/models/github_model.rb +++ b/app/models/github_model.rb @@ -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 + sleep client.rate_limit.resets_in + 1 + retry + end + nil rescue GitHub::Error nil end @@ -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 + sleep client.rate_limit.resets_in + 1 + retry + end + nil rescue GitHub::Error nil end