retry

package
v0.0.0-...-0f66f00 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 28, 2020 License: BSD-2-Clause Imports: 6 Imported by: 1

Documentation

Overview

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

Index

Constants

This section is empty.

Variables

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

Functions

This section is empty.

Types

type Attempt

type Attempt struct {
	Start time.Time
	Count uint
	Err   error
	*http.Request
	*http.Response
}

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

type Decision

type Decision int

Decision signals the intent of a Retryer

const (
	Ignore Decision = iota
	Retry
	Abort
)

type Delayer

type Delayer func(Attempt)

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

func Constant

func Constant(delta time.Duration) Delayer

Constant sleeps for delta duration

func Exponential

func Exponential(base time.Duration) Delayer

Linear sleeps for delta * 2^attempts

func Fibonacci

func Fibonacci(delta time.Duration) Delayer

Fibonacci sleeps for delta * fib(attempts)

func Linear

func Linear(delta time.Duration) Delayer

Linear sleeps for delta * the number of attempts

type MaxError

type MaxError struct {
	// contains filtered or unexported fields
}

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

func (MaxError) Error

func (e MaxError) Error() string

type Retryer

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

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

func EOF() Retryer

EOF retries only when the error is EOF

func Errors

func Errors() Retryer

Errors returns Retry when the attempt produced an error.

func Idempotent

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

func Max(limit uint) Retryer

Max errors after a limited number of attempts

func Method

func Method(methods ...string) Retryer

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

func Net

func Net() Retryer

Net retries errors returned by the 'net' package.

func Over

func Over(statusCode int) Retryer

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

func Temporary

func Temporary() Retryer

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

func Timeout

func Timeout(limit time.Duration) Retryer

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

type TimeoutError

type TimeoutError struct {
	// contains filtered or unexported fields
}

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

func (TimeoutError) Error

func (e TimeoutError) Error() string

type Transport

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

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL