Module: HTTPX::Plugins::Retries
- Defined in:
- lib/httpx/plugins/retries.rb
Overview
This plugin adds support for retrying requests when errors happen.
It has a default max number of retries (see MAX_RETRIES and the max_retries option), after which it will return the last response, error or not. It will not raise an exception.
It does not retry which are not considered idempotent (see retry_change_requests to override).
Defined Under Namespace
Modules: InstanceMethods, OptionsMethods, RequestMethods, ResponseMethods
Constant Summary collapse
- MAX_RETRIES =
3- IDEMPOTENT_METHODS =
TODO: pass max_retries in a configure/load block
%w[GET OPTIONS HEAD PUT DELETE].freeze
- RECONNECTABLE_ERRORS =
subset of retryable errors which are safe to retry when reconnecting
[ IOError, EOFError, Errno::ECONNRESET, Errno::ECONNABORTED, Errno::EPIPE, Errno::EINVAL, Errno::ETIMEDOUT, ConnectionError, TLSError, Connection::HTTP2::Error, ].freeze
- RETRYABLE_ERRORS =
(RECONNECTABLE_ERRORS + [ Parser::Error, TimeoutError, ]).freeze
- DEFAULT_JITTER =
->(interval) { interval * ((rand + 1) * 0.5) }.freeze
- BACKOFF_ALGORITHMS =
list of supported backoff algorithms
%i[exponential_backoff polynomial_backoff].freeze
Class Method Summary collapse
-
.retry_after_exponential_backoff(request, _) ⇒ Object
returns the time to wait before resending
requestas per the exponential backoff retry strategy. -
.retry_after_polynomial_backoff(request, _) ⇒ Object
returns the time to wait before resending
requestas per the polynomial backoff retry strategy.
Instance Method Summary collapse
Class Method Details
.retry_after_exponential_backoff(request, _) ⇒ Object
returns the time to wait before resending request as per the exponential backoff retry strategy.
63 64 65 66 |
# File 'lib/httpx/plugins/retries.rb', line 63 def retry_after_exponential_backoff(request, _) offset = request..max_retries - request.retries (offset - 1) * 2 end |
.retry_after_polynomial_backoff(request, _) ⇒ Object
returns the time to wait before resending request as per the polynomial backoff retry strategy.
57 58 59 60 |
# File 'lib/httpx/plugins/retries.rb', line 57 def retry_after_polynomial_backoff(request, _) offset = request..max_retries - request.retries 2 * (offset - 1) end |
Instance Method Details
#extra_options(options) ⇒ Object
47 48 49 |
# File 'lib/httpx/plugins/retries.rb', line 47 def () .merge(max_retries: MAX_RETRIES) end |