1
0
Fork 0
mirror of https://github.com/fog/fog-aws.git synced 2022-11-09 13:50:52 -05:00

ET-2352 Implements exponential backoff for compute requests.

No new test failures.
This commit is contained in:
Michael Sawyer 2017-04-20 13:38:23 -07:00
parent c188fa8018
commit 31136f1654

View file

@ -537,7 +537,10 @@ module Fog
end end
end end
def _request(body, headers, idempotent, parser) def _request(body, headers, idempotent, parser, retries = 0)
max_retries = 10
@connection.request({ @connection.request({
:body => body, :body => body,
:expects => 200, :expects => 200,
@ -552,6 +555,13 @@ module Fog
raise case match[:code] raise case match[:code]
when 'NotFound', 'Unknown' when 'NotFound', 'Unknown'
Fog::Compute::AWS::NotFound.slurp(error, match[:message]) Fog::Compute::AWS::NotFound.slurp(error, match[:message])
when 'RequestLimitExceeded'
if retries < max_retries
sleep (2.0 ** (1.0 + retries) * 100) / 1000.0
_request(body, headers, idempotent, parser, retries + 1)
else
Fog::Compute::AWS::Error.slurp(error, "Max retries exceeded (#{max_retries}) #{match[:code]} => #{match[:message]}")
end
else else
Fog::Compute::AWS::Error.slurp(error, "#{match[:code]} => #{match[:message]}") Fog::Compute::AWS::Error.slurp(error, "#{match[:code]} => #{match[:message]}")
end end