Documentation ¶
Index ¶
- Variables
- func Call(ctx context.Context, callable Callable, options ...Option) (interface{}, error)
- func Call2(ctx context.Context, callable2 Callable2, options ...Option) (interface{}, interface{}, error)
- func Run(ctx context.Context, runnable Runnable, options ...Option) error
- func SetDefaultOptions(options ...Option)
- type Backoff
- func NewConstantBackoff(delay time.Duration) Backoff
- func NewConstantBackoff2(config ConstantBackoffConfig) Backoff
- func NewExponentialBackoff(config ExponentialBackoffConfig) Backoff
- func NewFibonacciBackoff2(config FibonacciConfig) Backoff
- func NewLinearBackoff(baseDelay time.Duration) Backoff
- func NewLinearBackoff2(config LinearBackoffConfig) Backoff
- type Callable
- type Callable2
- type Callback
- type Callback2
- type Config
- type ConstantBackoffConfig
- type ExponentialBackoffConfig
- type FibonacciConfig
- type LinearBackoffConfig
- type LoggerFunc
- type Option
- type Retry
- type Runnable
- type State
Constants ¶
This section is empty.
Variables ¶
var (
ConstantBackoff = NewConstantBackoff(defaultBaseDelay)
)
var ( DefaultRecoverableErrorPredicate = func(err error) bool { return !(errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded)) } )
var ( ExponentialBackoff = NewExponentialBackoff(ExponentialBackoffConfig{ Multiplier: 2.0, Jitter: defaultJitterFactor, BaseDelay: defaultBaseDelay, MaxDelay: 30 * time.Second, }) )
var ( FibonacciBackoff = NewFibonacciBackoff2(FibonacciConfig{ Delay: defaultBaseDelay, MaxDelay: 30 * time.Second, Jitter: defaultJitterFactor, }) )
var (
LinearBackoff = NewLinearBackoff(defaultBaseDelay)
)
Functions ¶
func Call2 ¶
func Call2(ctx context.Context, callable2 Callable2, options ...Option) (interface{}, interface{}, error)
Call2 is a syntactic sugar
func SetDefaultOptions ¶
func SetDefaultOptions(options ...Option)
Types ¶
type Backoff ¶
type Backoff interface { // NextDelay returns the amount of time to wait before the next // retry given the specified number of consecutive failures. NextDelay(failures int) time.Duration }
Backoff defines the backoff abstraction, NB: Implementations must be safe for concurrent use
func NewConstantBackoff ¶
NewConstantBackoff returns a Backoff that delays with the specified duration between failures
func NewConstantBackoff2 ¶
func NewConstantBackoff2(config ConstantBackoffConfig) Backoff
NewConstantBackoff2 returns a Backoff that delays with a linear pattern between failures
func NewExponentialBackoff ¶
func NewExponentialBackoff(config ExponentialBackoffConfig) Backoff
NewExponentialBackoff returns a Backoff that delays with an exponential pattern between failures
func NewFibonacciBackoff2 ¶
func NewFibonacciBackoff2(config FibonacciConfig) Backoff
NewFibonacciBackoff2 returns a Backoff that returns FibonacciBackoff sequenced wait delays between failures
func NewLinearBackoff ¶
NewLinearBackoff returns a Backoff that delays with a linear pattern between failures
func NewLinearBackoff2 ¶
func NewLinearBackoff2(config LinearBackoffConfig) Backoff
NewLinearBackoff2 returns a Backoff that delays in a linear pattern between failures
type ConstantBackoffConfig ¶
type ExponentialBackoffConfig ¶
type ExponentialBackoffConfig struct { // BaseDelay is the amount of time to backoff after the first failure. BaseDelay time.Duration // Multiplier is the factor with which to multiply backoff after a // failed retry. Should ideally be greater than 1. Multiplier float64 // Jitter is the factor with which the delays are randomized. Jitter float64 // MaxDelay is the upper bound of backoff delay. MaxDelay time.Duration }
type FibonacciConfig ¶
type LinearBackoffConfig ¶
type LoggerFunc ¶
type LoggerFunc func(template string, args ...interface{})
type Option ¶
type Option interface {
Apply(c *Config)
}
func WithBackoff ¶
WithBackoff set the retry backoff algorithm to use. Default is LinearBackoff
func WithMaxAttempts ¶
WithMaxAttempts set the max retry attempts before giving up; < 0 means keep retrying "forever" Note, attempt semantics begins after the first execution. Default is 3
func WithRecoverableErrorPredicate ¶
WithRecoverableErrorPredicate set the predicate use to test whether an error is recoverable or not before a retry is scheduled. The default ensures the error is neither context.Canceled nor context.DeadlineExceeded
func WithTaskName ¶
WithTaskName name of the task useful for debugging...