retry

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxAttempts is the max attempts
	MaxAttempts = 99999999
)

Variables

View Source
var (
	// ErrTimeout indicates the operation has been timed out
	ErrTimeout = errors.New("operation has timed out")
	// ErrCancelled indicates the operaton was cancelled
	ErrCancelled = errors.New("operation has been cancelled")
)
View Source
var (
	// ErrReachMaxAttempts indicates we hit the limit
	ErrReachMaxAttempts = errors.New("reached max attempts")
)

Functions

func Forever

func Forever(ctx context.Context, interval time.Duration, method func())

Forever is called on interval for eternity or until cancelled

func IsRetryFailed

func IsRetryFailed(err error) bool

IsRetryFailed will return true if the supplied error is one that the Retry / RetryWithTimeout / RetryErrors functions will return if the retry did not succeed within the specified time/number of attempts.

func Retry

func Retry(ctx context.Context, attempts int, jitter bool, minInterval time.Duration, retryFn RetryFunc) error

Retry is used to retry an operation multiple times under a context. If the retryFn returns false with no error, the operation will be retried.

func RetryWithTimeout

func RetryWithTimeout(ctx context.Context, timeout, interval time.Duration, retryFn RetryFunc) error

RetryWithTimeout creates a retry with a specific timeout

func WaitUntilComplete

func WaitUntilComplete(ctx context.Context, timeout time.Duration, interval time.Duration, condition func() (bool, error)) error

WaitUntilComplete calls the condition on every interval and check for true, nil. An error indicates a hard error and exits

Types

type RetryFunc

type RetryFunc func() (bool, error)

RetryFunc performs the operation. It should return true if the operation is complete, false if it should be retried, and an error if an error which should NOT be retried has occurred.

Jump to

Keyboard shortcuts

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