handy: github.com/streadway/handy/retry Index | Files

package retry

import "github.com/streadway/handy/retry"

Package retry implements a retrying transport based on a combination of strategies.


Package Files

delay.go retry.go strategy.go


var DefaultRetryer = All(Max(10), Timeout(30*time.Second), EOF(), Over(300))

type Attempt Uses

type Attempt struct {
    Start time.Time
    Count uint
    Err   error

Attempt counts the round trips issued, starting from 1. Response is valid only when Err is nil.

type Decision Uses

type Decision int

Decision signals the intent of a Retryer

const (
    Ignore Decision = iota

type Delayer Uses

type Delayer func(Attempt)

Delayer sleeps or selects any amount of time for each attempt.

func Constant Uses

func Constant(delta time.Duration) Delayer

Constant sleeps for delta duration

func Exponential Uses

func Exponential(base time.Duration) Delayer

Linear sleeps for delta * 2^attempts

func Fibonacci Uses

func Fibonacci(delta time.Duration) Delayer

Fibonacci sleeps for delta * fib(attempts)

func Linear Uses

func Linear(delta time.Duration) Delayer

Linear sleeps for delta * the number of attempts

type MaxError Uses

type MaxError struct {
    // contains filtered or unexported fields

MaxError is returned from RoundTrip when the maximum attempts has been reached.

func (MaxError) Error Uses

func (e MaxError) Error() string

type Retryer Uses

type Retryer func(Attempt) (Decision, error)

Retryer chooses whether or not to retry this request. The error is only valid when the Retyer returns Abort.

func All Uses

func All(conditions ...Retryer) Retryer

All aggregates decisions from Retryers for an attempt. All returns Abort and the error on the first Abort. If at least one returns Retry All returns Retry with nil error. Otherwise All returns Ignore with nil error.

func EOF Uses

func EOF() Retryer

EOF retries only when the error is EOF

func Errors Uses

func Errors() Retryer

Errors returns Retry when the attempt produced an error.

func Idempotent Uses

func Idempotent() Retryer

Idempotent retries when the request is expected to be idempotent according to RFC 2616, section 9.1.2. https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.1.2

func Max Uses

func Max(limit uint) Retryer

Max errors after a limited number of attempts

func Method Uses

func Method(methods ...string) Retryer

Method retries when the request method is one of the given methods

func Net Uses

func Net() Retryer

Net retries errors returned by the 'net' package.

func Over Uses

func Over(statusCode int) Retryer

Over retries when a response is missing or the status code is over a value like 300

func Temporary Uses

func Temporary() Retryer

Temporary retries if the error implements Temporary() bool and returns true or aborts if returning false.

func Timeout Uses

func Timeout(limit time.Duration) Retryer

Timeout errors after a duration of time passes since the first attempt.

type TimeoutError Uses

type TimeoutError struct {
    // contains filtered or unexported fields

TimeoutError is returned from RoundTrip when the time limit has been reached.

func (TimeoutError) Error Uses

func (e TimeoutError) Error() string

type Transport Uses

type Transport struct {
    // Delay is called for attempts that are retried.  If nil, no delay will be used.
    Delay Delayer

    // Retry is called for every attempt
    Retry Retryer

    // Next is called for every attempt
    Next http.RoundTripper

func (Transport) RoundTrip Uses

func (t Transport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip delegates a RoundTrip, then determines via Retry whether to retry and Delay for the wait time between attempts.

Package retry imports 6 packages (graph) and is imported by 1 packages. Updated 2020-01-29. Refresh now. Tools for package owners.