Class: HTTP::Retriable::Performer Private
- Inherits:
-
Object
- Object
- HTTP::Retriable::Performer
- Defined in:
- lib/http/retriable/performer.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.
Request performing watchdog.
Constant Summary collapse
- RETRIABLE_ERRORS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Exceptions we should retry
[ HTTP::TimeoutError, HTTP::ConnectionError, IO::EAGAINWaitReadable, Errno::ECONNRESET, Errno::ECONNREFUSED, Errno::EHOSTUNREACH, OpenSSL::SSL::SSLError, EOFError, IOError ].freeze
Instance Method Summary collapse
-
#calculate_delay(iteration, response) ⇒ Numeric
private
Calculates delay between retries.
-
#initialize(tries: 5, delay: nil, exceptions: RETRIABLE_ERRORS, retry_statuses: nil, on_retry: ->(*_args) {}, max_delay: Float::MAX, should_retry: nil) ⇒ HTTP::Retriable::Performer
constructor
private
Create a new retry performer.
-
#perform(client, req, &block) ⇒ HTTP::Response
private
Execute request with retry logic.
Constructor Details
#initialize(tries: 5, delay: nil, exceptions: RETRIABLE_ERRORS, retry_statuses: nil, on_retry: ->(*_args) {}, max_delay: Float::MAX, should_retry: nil) ⇒ HTTP::Retriable::Performer
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 new retry performer
38 39 40 41 42 43 44 45 46 |
# File 'lib/http/retriable/performer.rb', line 38 def initialize(tries: 5, delay: nil, exceptions: RETRIABLE_ERRORS, retry_statuses: nil, on_retry: ->(*_args) {}, max_delay: Float::MAX, should_retry: nil) @exception_classes = exceptions @retry_statuses = retry_statuses @tries = tries.to_i @on_retry = on_retry @should_retry_proc = should_retry @delay_calculator = DelayCalculator.new(delay: delay, max_delay: max_delay) end |
Instance Method Details
#calculate_delay(iteration, response) ⇒ Numeric
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.
Calculates delay between retries
73 74 75 |
# File 'lib/http/retriable/performer.rb', line 73 def calculate_delay(iteration, response) @delay_calculator.call(iteration, response) end |
#perform(client, req, &block) ⇒ HTTP::Response
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.
Execute request with retry logic
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/http/retriable/performer.rb', line 53 def perform(client, req, &block) 1.upto(Float::INFINITY) do |attempt| # infinite loop with index err, res = try_request(&block) if retry_request?(req, err, res, attempt) retry_attempt(client, req, err, res, attempt) elsif err finish_attempt(client, err) elsif res return res end end end |