Class: Puppet::HTTP::RetryAfterHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet/http/retry_after_handler.rb

Instance Method Summary collapse

Constructor Details

#initialize(retry_limit, max_sleep) ⇒ RetryAfterHandler

Returns a new instance of RetryAfterHandler


5
6
7
8
# File 'lib/puppet/http/retry_after_handler.rb', line 5

def initialize(retry_limit, max_sleep)
  @retry_limit = retry_limit
  @max_sleep = max_sleep
end

Instance Method Details

#retry_after?(request, response) ⇒ Boolean

Returns:

  • (Boolean)

10
11
12
13
14
15
16
17
# File 'lib/puppet/http/retry_after_handler.rb', line 10

def retry_after?(request, response)
  case response.code
  when 429, 503
    true
  else
    false
  end
end

#retry_after_interval(request, response, retries) ⇒ Object


19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/puppet/http/retry_after_handler.rb', line 19

def retry_after_interval(request, response, retries)
  raise Puppet::HTTP::TooManyRetryAfters.new(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