Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Immediately = FixedConfig{}
Immediately means retry without any delays
Functions ¶
func Do ¶
Do executes the given function, retrying if necessary.
The given Config is used to calculate the delays before each attempt.
Wrap an error with Retriable to indicate that Do should try again.
If the function returns success, or an error that isn't wrapped, Do returns that value immediately without trying more.
A RetriableError error will be logged unless its message is exactly the same as the previous one.
func Retriable ¶ added in v0.8.0
Retriable wraps an error to tell Do that it should keep trying. Returns nil if err is nil.
Types ¶
type Config ¶ added in v0.8.0
type Config interface { // Delays returns a DelayFn representing the sequence of delays to use between attempts. // Each call to Delays returns a DelayFn representing an independent sequence. Delays() DelayFn }
Config defines retry intervals.
An implementation of Config is normally stateless.
type DelayFn ¶ added in v0.8.0
DelayFn is the type of function that can be called repeatedly to produce delays between attempts. A single value of DelayFn represents a single sequence of delays.
Each call returns the delay before the next attempt, and a boolean value to indicate whether the next attempt is desired. If ok is false, the caller should stop trying and ignore the returned delay value. The caller is not expected to call the function again after receiving false.
In other words, a DelayFn returns a finite or infinite sequence of delays over multiple calls. A false value of the second return value means the end of the sequence.
-- Hey delay function, should I make an attempt? -- Yes, in two seconds (2*time.Second, true). -- Hey delay function, should I make an attempt? -- Yes, in four seconds (4*time.Second, true). -- Hey delay function, should I make an attempt? -- No (0, false).
The delay function must return true as ok from the first call.
Note that the first delay returned by the function is used before the very first attempt. For this reason, in most cases, the first call should return (0, true).
type FixedConfig ¶ added in v0.8.0
type FixedConfig struct { // TryAfter is the delay before the first attempt TryAfter time.Duration // RetryAfter is the delay before each subsequent attempt RetryAfter time.Duration // MaxAttempts is the maximum number of attempts taken; 0 = unlimited MaxAttempts int }
FixedConfig defines fixed retry intervals
func (FixedConfig) Delays ¶ added in v0.8.0
func (c FixedConfig) Delays() DelayFn
Delays implements interface Config
type RetriableError ¶ added in v0.8.0
type RetriableError struct {
// contains filtered or unexported fields
}
RetriableError means the operation that caused the error should be retried.
func (RetriableError) Error ¶ added in v0.8.0
func (r RetriableError) Error() string
func (RetriableError) Unwrap ¶ added in v0.8.0
func (r RetriableError) Unwrap() error
Unwrap returns the next error in the error chain.