retry

package
v0.48.0 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package retry implements retry functionality.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do(ctx context.Context, maxDuration time.Duration, fn func() error, matches ...MatchFunc) error

Do implements retry using fibonacci backoff, up to a total execution time of maxDuration (use zero to indicate no max). The maximum interval between retries is 5 seconds.

If len(matches) is zero, retry will be attempted until ctx is canceled or times out, or maxDuration is reached. If one or more MatchFuncs are supplied, retry is performed only if the error returned by fn is matched by one of the MatchFunc args.

For simple string matching, use retry.Match("value") for convenience.

err = retry.Do(ctx, time.Second*10, dbConnect, retry.Match("connection refused"))

func DoConstant added in v0.31.0

func DoConstant(ctx context.Context, interval, maxDuration time.Duration, fn func() error, matches ...MatchFunc) error

DoConstant is similar to Do, but uses a constant backoff instead of fibonacci.

func Jitter added in v0.31.0

func Jitter() time.Duration

Jitter returns some amount of jitter between 5ms and 25ms.

func SleepJitter added in v0.31.0

func SleepJitter()

SleepJitter sleeps for a jittery amount of time.

Types

type MatchFunc added in v0.31.0

type MatchFunc func(err error) bool

MatchFunc returns true if err matches a condition for retry.

func Match added in v0.31.0

func Match(s string) MatchFunc

Match is a MatchFunc that tests if the retry func's error string contains s.

Jump to

Keyboard shortcuts

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