retry

package
v0.62.0 Latest Latest
Warning

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

Go to latest
Published: Jan 12, 2021 License: MIT Imports: 5 Imported by: 14

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Loop added in v0.43.0

func Loop(action Action, strategies ...Strategy) error

Loop executes the provided action infinitely, until one of the provided strategies indicates it should not be retried.

Unlike Retry, when the action returns with no error, the internal attempt counter is reset, and the action is retried.

func Retry

func Retry(action Action, strategies ...Strategy) (uint, error)

Retry executes the provided action, potentially multiple times based off of the provided strategies. Retry will block until the action is successful, or one of the provided strategies indicate no further retries should be performed.

The strategies are executed in the provided order, so any strategies that induce delays should be specified last.

Types

type Action

type Action func() error

Action is a function to be performed in a retriable manner.

type Retrier

type Retrier interface {
	Retry(action Action) (uint, error)
}

Retrier retries the provided action.

func NewRetrier

func NewRetrier(strategies ...Strategy) Retrier

NewRetrier returns a Retrier that will retry actions based off of the provided strategies. If no strategies are provided, the retrier acts as a tight-loop, retrying until no error is returned from the action.

type Strategy

type Strategy func(attempts uint, err error) bool

Strategy is a function that determines whether or not an action should be retried. Strategies are allowed to delay or cause other side effects.

func Backoff

func Backoff(strategy backoff.Strategy, maxBackoff time.Duration) Strategy

Backoff returns a strategy that will delay the next retry, provided the action resulted in an error. The returned strategy will cause the caller (the retrier) to sleep.

func BackoffWithJitter

func BackoffWithJitter(strategy backoff.Strategy, maxBackoff time.Duration, jitter float64) Strategy

BackoffWithJitter returns a strategy similar to Backoff, but induces a jitter on the total delay. The maxBackoff is calculated before the jitter.

The jitter parameter is a percentage of the total delay (after capping) that the timing can be off of. For example, a capped delay of 100ms with a jitter of 0.1 will result in a delay of 100ms +/- 10ms.

func Limit

func Limit(maxAttempts uint) Strategy

Limit returns a strategy that limits the total number of retries. maxAttempts should be >= 1, since the action is evaluateed first.

func NonRetriableErrors

func NonRetriableErrors(nonRetriableErrors ...error) Strategy

NonRetriableErrors returns a strategy that specifies which errors should not be retried.

func RetriableErrors

func RetriableErrors(retriableErrors ...error) Strategy

RetriableErrors returns a strategy that specifies which errors can be retried.

Directories

Path Synopsis
Package backoff provides varies backoff strategies for retry.
Package backoff provides varies backoff strategies for retry.

Jump to

Keyboard shortcuts

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