-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
retry requests when rate limit reached (#315)
* retry requests when rate limit reached Adds support for retrying requests that fail with 429 using the `Retry-After` header, similar to what we do in godo. This is still WIP, since the README hasn't yet been update to describe the change in behaviour. I also still need to run some manual tests. * restore rate limit err when retry-after missing * remove support for ruby 2.5 (eol 31/03/2021) * only retry rate limits when enabled * document rate limit handling and config
- Loading branch information
1 parent
984e8e4
commit a43a704
Showing
11 changed files
with
134 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# frozen_string_literal: true | ||
|
||
shared_examples_for 'resource that handles rate limit retries' do | ||
let(:arguments) { {} } | ||
|
||
it 'handles rate limit' do | ||
response_body = { id: :rate_limit, message: 'example' } | ||
stub_do_api(path, method).to_return( | ||
[ | ||
{ | ||
body: nil, | ||
status: 429, | ||
headers: { | ||
'RateLimit-Limit' => 1200, | ||
'RateLimit-Remaining' => 1193, | ||
'RateLimit-Reset' => 1_402_425_459, | ||
'Retry-After' => 0 # Retry immediately in tests. | ||
} | ||
}, | ||
{ | ||
body: response_body.to_json, | ||
status: 200, | ||
headers: { | ||
'RateLimit-Limit' => 1200, | ||
'RateLimit-Remaining' => 1192, | ||
'RateLimit-Reset' => 1_402_425_459 | ||
} | ||
} | ||
] | ||
) | ||
|
||
expect { resource.send(action, arguments) }.not_to raise_error | ||
end | ||
end |