BackoffRetrier

public class BackoffRetrier : Retrier

The backoff retrier is a more complex, stateful retrier that retries a request upon certain failures by waiting a specified period of time defined by its strategy (see BackoffRetrier.Strategy). It also defines a maximum duration after which a failed request is deemed unsuccessful.

Static Methods

  • Initializes a new factory yielding instances of backoff retriers for requests.

    Declaration

    Swift

    public static func factory(
        strategy: Strategy = .exponentialBinary, maxBackoff: TimeInterval = 600,
        retryCondition: @escaping (Squid.Error) -> Bool = defaultRetryCondition
    ) -> RetrierFactory

    Parameters

    strategy

    The strategy to use for the backoff retrier. Defaults to .exponentialBinary.

    maxBackoff

    The maximum backoff duration. After this time, requests are not retried any more. Defaults to 10 minutes.

    retryCondition

    A closure evaluating whether to attempt a retry based on the error causing the request to fail. Defaults to defaultRetryCondition(_:).

  • Defines the default condition that a request is retried based on the error that has occured. Retrying by backing off is attempted in the case of:

    1. No Connection (i.e. bad internet)
    2. Timeout (i.e. server possibly down)
    3. Unknown Error
    4. Status Code 429 (i.e. throttling)

    Declaration

    Swift

    public static func defaultRetryCondition(_ error: Squid.Error) -> Bool

    Parameters

    error

    The error that caused the failure of the request, used to decide whether the request ought to be retried.

Retrier

  • Declaration

    Swift

    public func retry<R>(
        _ request: R, failingWith error: Squid.Error
    ) -> Future<Bool, Never> where R: Request
  • The strategy of a backoff retrier essentially defines the time to wait before repeating the request.

    See more

    Declaration

    Swift

    public enum Strategy
  • Declaration

    Swift

    public var allowsMultipleRetries: Bool { get }