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).
Classes and Modules
Constants
| BACKOFF_ALGORITHMS | = | %i[exponential_backoff polynomial_backoff].freeze |
list of supported backoff algorithms |
|
| DEFAULT_JITTER | = | ->(interval) { interval * ((rand + 1) * 0.5) }.freeze | ||
| IDEMPOTENT_METHODS | = | %w[GET OPTIONS HEAD PUT DELETE].freeze |
TODO: pass max_retries in a configure/load block |
|
| MAX_RETRIES | = | 3 | ||
| RECONNECTABLE_ERRORS | = | [ IOError, EOFError, Errno::ECONNRESET, Errno::ECONNABORTED, Errno::EPIPE, Errno::EINVAL, Errno::ETIMEDOUT, ConnectionError, TLSError, Connection::HTTP2::Error, ].freeze |
subset of retryable errors which are safe to retry when reconnecting |
|
| RETRYABLE_ERRORS | = | (RECONNECTABLE_ERRORS + [ Parser::Error, TimeoutError, ]).freeze |
Public Class methods
extra_options(options)
[show source]
# File lib/httpx/plugins/retries.rb 47 def extra_options(options) 48 options.merge(max_retries: MAX_RETRIES) 49 end
retry_after_exponential_backoff(request, _)
returns the time to wait before resending request as per the exponential backoff retry strategy.
[show source]
# File lib/httpx/plugins/retries.rb 63 def retry_after_exponential_backoff(request, _) 64 offset = request.options.max_retries - request.retries 65 (offset - 1) * 2 66 end
retry_after_polynomial_backoff(request, _)
returns the time to wait before resending request as per the polynomial backoff retry strategy.
[show source]
# File lib/httpx/plugins/retries.rb 57 def retry_after_polynomial_backoff(request, _) 58 offset = request.options.max_retries - request.retries 59 2 * (offset - 1) 60 end