Documentation ¶
Index ¶
- Constants
- func Stop(err error) error
- func Until(ctx context.Context, backOff BackOff, f Func) error
- type Async
- type AsyncItem
- type AttemptsBackOff
- type BackOff
- type ConstBackOff
- type Err
- type ExponentialBackOff
- func (b *ExponentialBackOff) CalcDuration(retries int64) time.Duration
- func (b *ExponentialBackOff) New() BackOff
- func (b *ExponentialBackOff) Next() (time.Duration, bool)
- func (b *ExponentialBackOff) NextIteration() time.Duration
- func (b *ExponentialBackOff) NumRetries() int
- func (b *ExponentialBackOff) Reset()
- type Func
Constants ¶
const ( Cancelled = cancelReason("context cancelled") Stopped = cancelReason("retry stopped") AttemptsExhausted = cancelReason("attempts exhausted") )
Variables ¶
This section is empty.
Functions ¶
func Stop ¶
Stop forces the retry to cancel with the provided error and retry.Err.Reason == retry.Stopped
Types ¶
type Async ¶
type Async struct {
// contains filtered or unexported fields
}
func NewRetryAsync ¶
func NewRetryAsync() *Async
Given a function that takes a context, run the provided function; if it fails, retry the function asynchronously and return Async{}. Subsequent calls to with the same 'key' will return Async{} if the function is still retrying, this continues until the retry period has exhausted or the context expires or is cancelled. Then the final error returned by f() is returned to the caller on the final call with the same 'key'
The code assumes the caller will continue to call `Async()` until either the retries have exhausted or an Async{Retrying: false} is returned.
type AttemptsBackOff ¶
type AttemptsBackOff struct { Interval time.Duration Attempts int64 // contains filtered or unexported fields }
AttemptsBackOff retry for `attempts` number of retries sleeping for `interval` between each retry
func (*AttemptsBackOff) CalcDuration ¶ added in v4.9.0
func (b *AttemptsBackOff) CalcDuration(retries int64) time.Duration
func (*AttemptsBackOff) New ¶
func (b *AttemptsBackOff) New() BackOff
func (*AttemptsBackOff) NextIteration ¶ added in v4.9.0
func (b *AttemptsBackOff) NextIteration() time.Duration
func (*AttemptsBackOff) NumRetries ¶
func (b *AttemptsBackOff) NumRetries() int
func (*AttemptsBackOff) Reset ¶
func (b *AttemptsBackOff) Reset()
type ConstBackOff ¶
ConstBackOff indefinitely retry, returns `interval` for each call to Next()
func Interval ¶
func Interval(t time.Duration) *ConstBackOff
func (*ConstBackOff) CalcDuration ¶ added in v4.9.0
func (b *ConstBackOff) CalcDuration(retries int64) time.Duration
func (*ConstBackOff) New ¶
func (b *ConstBackOff) New() BackOff
func (*ConstBackOff) NextIteration ¶ added in v4.9.0
func (b *ConstBackOff) NextIteration() time.Duration
func (*ConstBackOff) NumRetries ¶
func (b *ConstBackOff) NumRetries() int
func (*ConstBackOff) Reset ¶
func (b *ConstBackOff) Reset()
type ExponentialBackOff ¶
type ExponentialBackOff struct {
Min, Max time.Duration
Factor float64
Attempts int64
// contains filtered or unexported fields
}
func (*ExponentialBackOff) CalcDuration ¶ added in v4.9.0
func (b *ExponentialBackOff) CalcDuration(retries int64) time.Duration
CalcDuration returns the next duration to sleep given the number of retries.
This function is useful when keeping track of the attempts and attempt resets is external to our code.
func (*ExponentialBackOff) New ¶
func (b *ExponentialBackOff) New() BackOff
New returns a copy of the current backoff
func (*ExponentialBackOff) NextIteration ¶ added in v4.9.0
func (b *ExponentialBackOff) NextIteration() time.Duration
NextIteration returns the next backoff duration. Is identical to Next() but never indicates if we have reached our max attempts
func (*ExponentialBackOff) NumRetries ¶
func (b *ExponentialBackOff) NumRetries() int
func (*ExponentialBackOff) Reset ¶
func (b *ExponentialBackOff) Reset()