mirror of
https://github.com/fog/fog-aws.git
synced 2022-11-09 13:50:52 -05:00
Merge pull request #361 from VVMichaelSawyer/exponential_backoff
Exponential backoff
This commit is contained in:
commit
1577e12087
1 changed files with 20 additions and 5 deletions
|
@ -3,6 +3,8 @@ module Fog
|
|||
class AWS < Fog::Service
|
||||
extend Fog::AWS::CredentialFetcher::ServiceMethods
|
||||
|
||||
class RequestLimitExceeded < Fog::Errors::Error; end
|
||||
|
||||
requires :aws_access_key_id, :aws_secret_access_key
|
||||
recognizes :endpoint, :region, :host, :path, :port, :scheme, :persistent, :aws_session_token, :use_iam_profile, :aws_credentials_expire_at, :instrumentor, :instrumentor_name, :version
|
||||
|
||||
|
@ -537,7 +539,11 @@ module Fog
|
|||
end
|
||||
end
|
||||
|
||||
def _request(body, headers, idempotent, parser)
|
||||
def _request(body, headers, idempotent, parser, retries = 0)
|
||||
|
||||
max_retries = 10
|
||||
|
||||
begin
|
||||
@connection.request({
|
||||
:body => body,
|
||||
:expects => 200,
|
||||
|
@ -546,15 +552,24 @@ module Fog
|
|||
:method => 'POST',
|
||||
:parser => parser
|
||||
})
|
||||
rescue Excon::Errors::HTTPStatusError => error
|
||||
match = Fog::AWS::Errors.match_error(error)
|
||||
raise if match.empty?
|
||||
raise case match[:code]
|
||||
rescue Excon::Errors::HTTPStatusError => error
|
||||
match = Fog::AWS::Errors.match_error(error)
|
||||
raise if match.empty?
|
||||
raise case match[:code]
|
||||
when 'NotFound', 'Unknown'
|
||||
Fog::Compute::AWS::NotFound.slurp(error, match[:message])
|
||||
when 'RequestLimitExceeded'
|
||||
if retries < max_retries
|
||||
sleep (2.0 ** (1.0 + retries) * 100) / 1000.0
|
||||
retries += 1
|
||||
retry
|
||||
else
|
||||
Fog::Compute::AWS::RequestLimitExceeded.slurp(error, "Max retries exceeded (#{max_retries}) #{match[:code]} => #{match[:message]}")
|
||||
end
|
||||
else
|
||||
Fog::Compute::AWS::Error.slurp(error, "#{match[:code]} => #{match[:message]}")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue