Class: Puppet::HTTP::RetryAfterHandler Private
- Defined in:
- lib/puppet/http/retry_after_handler.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Parse information relating to responses containing a Retry-After headers
Instance Method Summary collapse
-
#initialize(retry_limit, max_sleep) ⇒ RetryAfterHandler
constructor
private
Create a handler to allow the system to sleep between HTTP requests.
-
#retry_after?(request, response) ⇒ Boolean
private
Does the response from the server tell us to wait until we attempt the next retry?.
-
#retry_after_interval(request, response, retries) ⇒ Integer
private
The amount of time to wait before attempting a retry.
Constructor Details
#initialize(retry_limit, max_sleep) ⇒ RetryAfterHandler
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Create a handler to allow the system to sleep between HTTP requests
14 15 16 17 |
# File 'lib/puppet/http/retry_after_handler.rb', line 14 def initialize(retry_limit, max_sleep) @retry_limit = retry_limit @max_sleep = max_sleep end |
Instance Method Details
#retry_after?(request, response) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Does the response from the server tell us to wait until we attempt the next retry?
29 30 31 32 33 34 35 36 |
# File 'lib/puppet/http/retry_after_handler.rb', line 29 def retry_after?(request, response) case response.code when 429, 503 true else false end end |
#retry_after_interval(request, response, retries) ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
The amount of time to wait before attempting a retry
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/puppet/http/retry_after_handler.rb', line 50 def retry_after_interval(request, response, retries) raise Puppet::HTTP::TooManyRetryAfters, request.uri if retries >= @retry_limit retry_after = response['Retry-After'] return nil unless retry_after seconds = parse_retry_after(retry_after) # if retry-after is far in the future, we could end up sleeping repeatedly # for 30 minutes, effectively waiting indefinitely, seems like we should wait # in total for 30 minutes, in which case this upper limit needs to be enforced # by the client. [seconds, @max_sleep].min end |