retry

package
v0.0.0-...-3ac4d91 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2024 License: Apache-2.0 Imports: 5 Imported by: 57

Documentation

Index

Constants

View Source
const (
	// DefaultTimeout the default timeout for the entire retry operation
	DefaultTimeout = time.Second * 30

	// DefaultDelay the default delay between successive retry attempts
	DefaultDelay = time.Millisecond * 10

	// DefaultConverge the default converge, requiring something to succeed one time
	DefaultConverge = 1
)

Variables

View Source
var ErrConditionNotMet = errors.New("expected condition not met")

Functions

func Until

func Until(fn func() bool, options ...Option) error

Until retries the given function until it returns true or hits the timeout

func UntilComplete

func UntilComplete(fn RetriableFunc, options ...Option) (any, error)

UntilComplete retries the given function, until there is a timeout, or until the function indicates that it has completed. Once complete, the returned value and error are returned.

func UntilOrFail

func UntilOrFail(t test.Failer, fn func() bool, options ...Option)

UntilOrFail calls Until, and fails t with Fatalf if it ends up returning an error

func UntilSuccess

func UntilSuccess(fn func() error, options ...Option) error

UntilSuccess retries the given function until success, timeout, or until the passed-in function returns nil.

func UntilSuccessOrFail

func UntilSuccessOrFail(t test.Failer, fn func() error, options ...Option)

UntilSuccessOrFail calls UntilSuccess, and fails t with Fatalf if it ends up returning an error

Types

type Option

type Option func(cfg *config)

Option for a retry operation.

func BackoffDelay

func BackoffDelay(delay time.Duration) Option

func Converge

func Converge(successes int) Option

Converge sets the number of successes in a row needed to count a success. This is useful to avoid the case where tests like `coin.Flip() == HEADS` will always return success due to random variance.

func Delay

func Delay(delay time.Duration) Option

Delay sets the delay between successive retry attempts.

func MaxAttempts

func MaxAttempts(attempts int) Option

MaxAttempts allows defining a maximum number of attempts. If unset, only timeout is considered.

func Message

func Message(errorMessage string) Option

Message defines a more detailed error message to use when failing

func Timeout

func Timeout(timeout time.Duration) Option

Timeout sets the timeout for the entire retry operation.

type RetriableFunc

type RetriableFunc func() (result any, completed bool, err error)

RetriableFunc a function that can be retried.

Jump to

Keyboard shortcuts

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