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 =
[ # Ancestor for Errno::X SystemCallError, # Might be caused by e.g. DNS failure SocketError, # HTTPClient transfer error HTTPClient::TimeoutError, HTTPClient::KeepAliveDisconnected, HTTPClient::BadResponseError, # Bad response 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.
30 31 32 33 |
# File 'lib/aptible/resource/default_retry_coordinator.rb', line 30 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
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/aptible/resource/default_retry_coordinator.rb', line 35 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 |