import "go.chromium.org/luci/common/retry"
defaults.go exponential.go limited.go retry.go
Stop is a sentinel value returned by a Iterator to indicate that no more attempts should be made.
Retry executes a function 'fn'. If the function returns an error, it will be re-executed according to a retry plan.
If a Factory is supplied, it will be called to generate a single retry Iterator for this Retry round. If nil, Retry will execute the target function exactly once regardless of return value.
If the supplied context is canceled, retry will stop executing. Retry will not execute the supplied function at all if the context is canceled when Retry is invoked.
If 'callback' is not nil, it will be invoked if an error occurs (prior to sleeping).
Callback is a callback function that Retry will invoke every time an attempt fails prior to sleeping.
LogCallback builds a Callback which logs a Warning with the opname, error and delay.
type ExponentialBackoff struct { Limited // Multiplier is the exponential growth multiplier. If < 1, a default of 2 // will be used. Multiplier float64 // MaxDelay is the maximum duration. If <= zero, no maximum will be enforced. MaxDelay time.Duration }
ExponentialBackoff is an Iterator implementation that implements exponential backoff retry.
Next implements Iterator.
Factory is a function that produces an independent Iterator instance.
Since each Iterator is mutated as it is iterated through, this is used to produce a fresh Iterator for a new round of retries. Unless the caller is fully aware of what they're doing, this should not return the an Iterator instance more than once.
type Iterator interface { // Returns the next retry delay, or Stop if no more retries should be made. Next(context.Context, error) time.Duration }
Iterator describes a stateful implementation of retry logic.
Default is a Factory that returns a new instance of the default iterator configuration.
NewIterator creates an Iterator based on a "next" function. It is a concise way to implement an Iterator.
None is a Factory that returns an Iterator that explicitly calls Stop after the first try. This is helpful to pass to libraries which use retry.Default if given nil, but where you don't want any retries at all (e.g. tests).
type Limited struct { // Delay is the next generated delay. Delay time.Duration // Retries, if >= 0, is the number of remaining retries. If <0, no retry // count will be applied. Retries int // MaxTotal is the maximum total elapsed time. If <= 0, no maximum will be // enforced. MaxTotal time.Duration // contains filtered or unexported fields }
Limited is an Iterator implementation that may be limited by a maximum number of retries and/or time.
Next implements the Iterator interface.
Path | Synopsis |
---|---|
transient | Package transient allows you to tag and retry 'transient' errors (i.e. |
Package retry imports 4 packages (graph) and is imported by 63 packages. Updated 2021-01-26. Refresh now. Tools for package owners.