Class: Aptible::Resource::DefaultRetryCoordinator
- Inherits:
-
Object
- Object
- Aptible::Resource::DefaultRetryCoordinator
- 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
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
-
#retry_schedule ⇒ Object
readonly
Returns the value of attribute retry_schedule.
Instance Method Summary collapse
-
#initialize(resource) ⇒ DefaultRetryCoordinator
constructor
A new instance of DefaultRetryCoordinator.
- #retry?(method, err) ⇒ Boolean
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
#resource ⇒ Object (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_schedule ⇒ Object (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
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 |