retry

package
v0.0.0-...-a14a4d2 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrRetryTimeout timeout error for retrying
	ErrRetryTimeout = errors.New("retry timeout")
)

Functions

func Abort

func Abort(err error) error

Abort wrap err to stop the Retry function

func Retry

func Retry(f func() error, options ...Option) error

Retry retry until f run successfully or timeout

NOTE: This function will use exponential backoff and jitter for retrying, see https://aws.amazon.com/blogs/architecture/exponential-backoff-and-jitter/ for more information

Types

type Option

type Option func(*Options)

Option ...

func Backoff

func Backoff(backoff bool) Option

Backoff set backoff

func Callback

func Callback(callback func(err error, sleep time.Duration)) Option

Callback set callback

func InitialInterval

func InitialInterval(initial time.Duration) Option

InitialInterval set initial interval

func MaxInterval

func MaxInterval(max time.Duration) Option

MaxInterval set max interval

func Timeout

func Timeout(timeout time.Duration) Option

Timeout set timeout interval

type Options

type Options struct {
	InitialInterval time.Duration                        // the initial interval for retring after failure, default 100 milliseconds
	MaxInterval     time.Duration                        // the max interval for retring after failure, default 1 second
	Timeout         time.Duration                        // the total time before returning if something is wrong, default 1 minute
	Callback        func(err error, sleep time.Duration) // the callback function for Retry when the f called failed
	Backoff         bool
}

Options options for the retry functions

Jump to

Keyboard shortcuts

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