retry

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2025 License: MIT Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BackoffStrategyDefault = backoff.Backoff{
	Min:    100 * time.Millisecond,
	Max:    3 * time.Second,
	Factor: 2,
}

Exponential backoff (default) is used to handle retries with increasing wait times in case of errors

Functions

func CtxWithID

func CtxWithID(ctx context.Context, retryID string) context.Context

func Do

func Do[R any](ctx context.Context, lggr logger.Logger, fn func(ctx context.Context) (R, error)) (R, error)

Do applies a default retry strategy to a given function.

Types

type Strategy

type Strategy[R any] struct {
	Backoff *backoff.Backoff

	// MaxRetries is the number of attempts to call a function that has errored.
	// A default 0 value retries indefinitely until the context is canceled.
	// Every function is called at least once.
	MaxRetries uint
}

func (*Strategy[R]) Do

func (s *Strategy[R]) Do(ctx context.Context, lggr logger.Logger, fn func(ctx context.Context) (R, error)) (R, error)

Do executes a func according to the strategy.

Jump to

Keyboard shortcuts

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