Class Faraday::Request::Retry
In: lib/faraday/request/retry.rb
Parent: Faraday::Middleware

Catches exceptions and retries each request a limited number of times.

By default, it retries 2 times and handles only timeout exceptions. It can be configured with an arbitrary number of retries, a list of exceptions to handle, a retry interval, a percentage of randomness to add to the retry interval, and a backoff factor.

Examples

  Faraday.new do |conn|
    conn.request :retry, max: 2, interval: 0.05,
                         interval_randomness: 0.5, backoff_factor: 2
                         exceptions: [CustomException, 'Timeout::Error']
    conn.adapter ...
  end

This example will result in a first interval that is random between 0.05 and 0.075 and a second interval that is random between 0.1 and 0.15

Methods

Classes and Modules

Class Faraday::Request::Retry::Options

Constants

IDEMPOTENT_METHODS = [:delete, :get, :head, :options, :put]

Public Class methods

Public: Initialize middleware

Options: max - Maximum number of retries (default: 2) interval - Pause in seconds between retries (default: 0) interval_randomness - The maximum random interval amount expressed

                      as a float between 0 and 1 to use in addition to the
                      interval. (default: 0)

max_interval - An upper limit for the interval (default: Float::MAX) backoff_factor - The amount to multiple each successive retry‘s

                      interval amount by in order to provide backoff
                      (default: 1)

exceptions - The list of exceptions to handle. Exceptions can be

                      given as Class, Module, or String. (default:
                      [Errno::ETIMEDOUT, Timeout::Error,
                      Error::TimeoutError])

methods - A list of HTTP methods to retry without calling retry_if. Pass

                      an empty Array to call retry_if for all exceptions.
                      (defaults to the idempotent HTTP methods in IDEMPOTENT_METHODS)

retry_if - block that will receive the env object and the exception raised

                      and should decide if the code should retry still the action or
                      not independent of the retry count. This would be useful
                      if the exception produced is non-recoverable or if the
                      the HTTP method called is not idempotent.
                      (defaults to return false)

Public Instance methods

Private: construct an exception matcher object.

An exception matcher for the rescue clause can usually be any object that responds to `===`, but for Ruby 1.8 it has to be a Class or Module.

[Validate]