Documentation
¶
Overview ¶
Package retry contains utilities for retrying an action until it succeeds.
Index ¶
- type Condition
- type Listener
- type Retry
- func (r *Retry) Attempts(n 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) 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 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.
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.
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.