Documentation ¶
Overview ¶
Package retry contains utilities for retrying an action until it succeeds.
Index ¶
- type Condition
- type Error
- type Listener
- type Retry
- func (r *Retry) Attempts(maxAttempts int) *Retry
- func (r *Retry) Backoff(ceil time.Duration) *Retry
- func (r *Retry) Condition(fn Condition) *Retry
- func (r *Retry) Conditions(fns ...Condition) *Retry
- func (r *Retry) Context(ctx context.Context) *Retry
- func (r *Retry) ContinueOnNil() *Retry
- func (r *Retry) Jitter(rat float64) *Retry
- func (r *Retry) Log(logFn func(error)) *Retry
- func (r *Retry) Run(fn func() error) error
- func (r *Retry) Timeout(to time.Duration) *Retry
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Condition ¶
Condition is a function that decides based on the given error whether to retry.
func NotOnErrors ¶
NotOnErrors returns a condition which retries only if the error does not match one of the provided errors.
type Error ¶ added in v1.2.0
Error combines the reason the retry cancelled, and the error from the last call to Run.
type Retry ¶
type Retry struct {
// contains filtered or unexported fields
}
Retry holds state about a retryable operation. Callers should create this via New.
func (*Retry) Attempts ¶
Attempts sets the maximum amount of retry attempts before the current error is returned. If maxAttempts is 0, then r.Run() will return a nil error on any call.
func (*Retry) Backoff ¶
Backoff turns retry into an exponential backoff with a maximum sleep of ceil.
func (*Retry) Condition ¶
Condition appends the passed retry condition. The condition must return true for the retry to progress. Deprecated: Use Conditions instead.
func (*Retry) Conditions ¶
Condition appends the passed retry conditions. All conditions must return true for the retry to progress. The error passed to the retry conditions will be the result of errors.Cause() on the original error from the run function.
func (*Retry) ContinueOnNil ¶ added in v1.2.0
ContinueOnNil makes the retry continue even if the run function returns nil. You will need to set explicit conditions for the retry to exit.
func (*Retry) Jitter ¶
Jitter adds some random jitter to the retry's sleep.
Ratio must be between 0 and 1, and determines how jittery the sleeps will be. For example, a rat of 0.1 and a sleep of 1s restricts the jitter to the range of 900ms to 1.1 seconds.
func (*Retry) Log ¶
Log adds a function to log any returned errors. It is added as a post condition that always returns true. If you want an error to stop the retry and not be logged, use Log() after the Condition. If you want an error to stop the retry and be logged, use Log() before the Condition. Deprecated: Log in the Run function instead.