retry

package
v0.13.12 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 4 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultAttempts      = uint(10)
	DefaultDelay         = 100 * time.Millisecond
	DefaultMaxJitter     = 100 * time.Millisecond
	DefaultOnRetry       = func(_ uint, _ error) {}
	DefaultRetryIf       = IsRecoverable
	DefaultDelayType     = CombineDelay(FixedDelay, RandomDelay)
	DefaultLastErrorOnly = false
)

Functions

func BackOffDelay

func BackOffDelay(n uint, config *Config) time.Duration

BackOffDelay is a DelayType which increases delay between consecutive retries

func Do

func Do(retryFunc RetryableFunc, opts ...Option) error

func FixedDelay

func FixedDelay(_ uint, config *Config) time.Duration

FixedDelay is a DelayType which keeps delay the same through all iterations

func IsRecoverable

func IsRecoverable(err error) bool

IsRecoverable checks if error is an instance of `unrecoverableError`

func RandomDelay

func RandomDelay(_ uint, config *Config) time.Duration

RandomDelay is a DelayType which picks a random delay up to config.maxJitter

func Unrecoverable

func Unrecoverable(err error) error

Unrecoverable wraps an error in `unrecoverableError` struct

Types

type AbortFunc added in v0.8.0

type AbortFunc func(error) bool

type Config

type Config struct {
	// contains filtered or unexported fields
}

type DelayTypeFunc

type DelayTypeFunc func(n uint, config *Config) time.Duration

func CombineDelay

func CombineDelay(delays ...DelayTypeFunc) DelayTypeFunc

CombineDelay is a DelayType the combines all of the specified delays into a new DelayTypeFunc

type Error

type Error []error

Error type represents list of errors in retry

func (Error) Error

func (e Error) Error() string

Error method return string representation of Error It is an implementation of error interface

func (Error) WrappedErrors

func (e Error) WrappedErrors() []error

WrappedErrors returns the list of errors that this Error is wrapping. It is an implementation of the `errwrap.Wrapper` interface in package [errwrap](https://github.com/hashicorp/errwrap) so that `retry.Error` can be used with that library.

type OnRetryFunc

type OnRetryFunc func(n uint, err error)

Function signature of OnRetry function n = count of attempts

type Option

type Option func(*Config)

Option represents an option for retry.

func Attempts

func Attempts(attempts uint) Option

Attempts set count of retry default is 10

func Delay

func Delay(delay time.Duration) Option

Delay set delay between retry default is 100ms

func DelayType

func DelayType(delayType DelayTypeFunc) Option

DelayType set type of the delay between retries default is BackOff

func LastErrorOnly

func LastErrorOnly(lastErrorOnly bool) Option

return the direct last error that came from the retried function default is false (return wrapped errors with everything)

func MaxDelay

func MaxDelay(maxDelay time.Duration) Option

MaxDelay set maximum delay between retry does not apply by default

func MaxJitter

func MaxJitter(maxJitter time.Duration) Option

MaxJitter sets the maximum random Jitter between retries for RandomDelay

func OnRetry

func OnRetry(onRetry OnRetryFunc) Option

func OnlyRetryIf added in v0.8.0

func OnlyRetryIf(abortFunc AbortFunc) Option

`abortFunc` return true means no further need to retry

type RetryableFunc

type RetryableFunc func() error

Jump to

Keyboard shortcuts

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