Class: Puppet::HTTP::RetryAfterHandler Private

Inherits:
Object
  • Object
show all
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

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

Parameters:

  • retry_limit (Integer)

    number of retries allowed

  • max_sleep (Integer)

    maximum sleep time allowed



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?

Parameters:

Returns:

  • (Boolean)

    Return true if the response code is 429 or 503, return false otherwise



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

Parameters:

  • request (Net::HTTP)
  • response (Puppet::HTTP::Response)
  • retries (Integer)

    number of retries attempted so far

Returns:

  • (Integer)

    the amount of time to wait

Raises:



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