retry

package
v0.0.0-...-ed9fe1d Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2018 License: BSD-3-Clause Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do(ctx context.Context, task func(context.Context) error, backoff Backoff, checker Checker) error

Do retries `task` function until it returns nil error. If task return an error, checker checks if the retry is needed afeter waitng by waiter.

func NewHTTPTransport

func NewHTTPTransport(base http.RoundTripper, checker HTTPChecker, backoff HTTPBackoff) http.RoundTripper

NewHTTPTransport returns a new http.RoundTripper instance for given checker and backoff configurations on top of base http.RoundTripper

Types

type Backoff

type Backoff interface {
	Calc(context.Context, int) time.Duration
}

Backoff is an interface to implement backoff algorithm

func ConstBackoff

func ConstBackoff(t time.Duration) Backoff

ConstBackoff return a Backoff to return a constant time.Duration backoff given by `t`

type Checker

type Checker interface {
	NeedRetry(context.Context, int, error) bool
}

Checker is an interface to check if a retry is needed or not.

func MaxRetries

func MaxRetries(max int) Checker

MaxRetries returns a Checker to check the number of retries is less than max.

func Until

func Until(t time.Time) Checker

Until returns a Checker to check the time is before `t`

type HTTPBackoff

type HTTPBackoff interface {
	Calc(int, *http.Request, *http.Response, error) time.Duration
}

HTTPBackoff is an http version of Backoff

func HTTPConstBackoff

func HTTPConstBackoff(t time.Duration) HTTPBackoff

HTTPConstBackoff is a http version of ConstBackoff

type HTTPChecker

type HTTPChecker interface {
	NeedRetry(int, *http.Request, *http.Response, error) bool
}

HTTPChecker is an http version of Checker

func HTTPAnd

func HTTPAnd(checkers ...HTTPChecker) HTTPChecker

HTTPAnd is a AND combination of multiple HTTPChecker instances.

func HTTPMaxRetry

func HTTPMaxRetry(max int) HTTPChecker

HTTPMaxRetry is an http version of MaxRetry

func HTTPResponseChecker

func HTTPResponseChecker(f func(resp *http.Response) bool) HTTPChecker

HTTPResponseChecker returns a HTTPChecker that checks *http.Response for retries

func HTTPServerErrorChecker

func HTTPServerErrorChecker() HTTPChecker

HTTPServerErrorChecker returns a HTTPChecker that needs retries when http status code >= 500

type HTTPTransport

type HTTPTransport struct {
	Base    http.RoundTripper
	Checker HTTPChecker
	Backoff HTTPBackoff
}

HTTPTransport is a type for http.Transport with retry

func (*HTTPTransport) RoundTrip

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

RoundTrip implements http.Transport#RoundTrip

Jump to

Keyboard shortcuts

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