Class: Aptible::Resource::DefaultRetryCoordinator

Inherits:
Object
  • Object
show all
Defined in:
lib/aptible/resource/default_retry_coordinator.rb

Constant Summary collapse

IDEMPOTENT_METHODS =
[
  # Idempotent as per RFC
  :delete, :get, :head, :options, :put,
  # Idempotent on our APIs
  :patch
].freeze
RETRY_ERRORS =
[Faraday::Error, HyperResource::ServerError].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource) ⇒ DefaultRetryCoordinator

Returns a new instance of DefaultRetryCoordinator.



14
15
16
17
# File 'lib/aptible/resource/default_retry_coordinator.rb', line 14

def initialize(resource)
  @resource = resource
  @retry_schedule = new_retry_schedule
end

Instance Attribute Details

#resourceObject (readonly)

Returns the value of attribute resource.



4
5
6
# File 'lib/aptible/resource/default_retry_coordinator.rb', line 4

def resource
  @resource
end

#retry_scheduleObject (readonly)

Returns the value of attribute retry_schedule.



4
5
6
# File 'lib/aptible/resource/default_retry_coordinator.rb', line 4

def retry_schedule
  @retry_schedule
end

Instance Method Details

#retry?(method, err) ⇒ Boolean

Returns:



19
20
21
22
23
24
25
26
27
28
# File 'lib/aptible/resource/default_retry_coordinator.rb', line 19

def retry?(method, err)
  # rubocop:disable Style/CaseEquality
  return false unless RETRY_ERRORS.any? { |c| c === err }
  return false unless IDEMPOTENT_METHODS.include?(method)
  retry_in = retry_schedule.shift
  return false if retry_in.nil?
  sleep retry_in
  true
  # rubocop:enable Style/CaseEquality
end