retry

package
v0.0.0-...-9dda5dc Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do[T any](ctx context.Context, maxAttempts int, strategy Strategy, op func() (T, error)) (T, error)

func Do2

func Do2[T, U any](ctx context.Context, maxAttempts int, strategy Strategy, op func() (T, U, error)) (T, U, error)

Types

type ErrFailedPermanently

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

func (*ErrFailedPermanently) Error

func (e *ErrFailedPermanently) Error() string

func (*ErrFailedPermanently) Unwrap

func (e *ErrFailedPermanently) Unwrap() error

type ExponentialStrategy

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

	// Max is the maximum amount of time to wait between attempts.
	Max time.Duration

	// MaxJitter is the maximum amount of random jitter to insert between attempts.
	// Jitter is added on top of the maximum, if the maximum is reached.
	MaxJitter time.Duration
}

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

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 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