backoff

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do(maxAttempts int, strategy Strategy, op Operation) error

Do performs the provided Operation up to maxAttempts times with delays in between each retry according to the provided Strategy.

Types

type ErrFailedPermanently

type ErrFailedPermanently struct {
	LastErr error
	// contains filtered or unexported fields
}

ErrFailedPermanently is an error raised by Do when the underlying Operation has been retried maxAttempts times.

func (*ErrFailedPermanently) Error

func (e *ErrFailedPermanently) Error() string

type ExponentialStrategy

type ExponentialStrategy struct {
	// Min is the minimum amount of time to wait between attempts in ms.
	Min float64

	// Max is the maximum amount of time to wait between attempts in ms.
	Max float64

	// MaxJitter is the maximum amount of random jitter to insert between
	// attempts in ms.
	MaxJitter int
}

ExponentialStrategy performs exponential backoff. The exponential backoff function is min(e.Min + (2^attempt * 1000) + randBetween(0, e.MaxJitter), e.Max)

func (*ExponentialStrategy) Duration

func (e *ExponentialStrategy) Duration(attempt int) time.Duration

type FixedStrategy

type FixedStrategy struct {
	Dur time.Duration
}

func (*FixedStrategy) Duration

func (f *FixedStrategy) Duration(attempt int) time.Duration

type Operation

type Operation func() error

Operation represents an operation that will be retried based on some backoff strategy if it fails.

type Strategy

type Strategy interface {
	// Duration returns how long to wait for a given retry attempt.
	Duration(attempt int) time.Duration
}

Strategy is used to calculate how long a particular Operation should wait between attempts.

func Exponential

func Exponential() Strategy

func Fixed

func Fixed(dur time.Duration) Strategy

Jump to

Keyboard shortcuts

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