Documentation ¶
Overview ¶
Package retry allows operations to be retried if they fail transiently. Retries are typically paired with a backoff algorithm.
Index ¶
- Variables
- func Done(err error) (bool, error)
- func DoneUnlessMarkedTransient(err error) (bool, error)
- func Repeat(err error) (bool, error)
- func RepeatUnlessMarkedUser(err error) (bool, error)
- func Wait(ctx context.Context, work WorkFunc, opts ...WaitOption) (err error)
- func WaitAsync(ctx context.Context, work WorkFunc, opts ...WaitOption) <-chan error
- type WaitOption
- type WaitOptionFunc
- type WaitOptions
- type WorkFunc
Constants ¶
This section is empty.
Variables ¶
var DefaultBackoffFactory = backoff.Build( backoff.Exponential(250*time.Millisecond, 2.0), backoff.MaxBound(30*time.Second), backoff.FullJitter(), backoff.NonSliding, )
DefaultBackoffFactory is a networking-appropriate backoff that the wait functions use by default. It provides a non-sliding exponential backoff starting at 250ms, factor 2, a 30 second cap, and full jitter using the default RNG.
Functions ¶
func DoneUnlessMarkedTransient ¶ added in v0.4.0
DoneUnlessMarkedTransient indicates that work should not be retried unless the given error is marked transient.
func RepeatUnlessMarkedUser ¶ added in v0.4.0
RepeatUnlessMarkedUser indicates that work should be retried if an error is provided and it is not marked as a user error.
func Wait ¶
func Wait(ctx context.Context, work WorkFunc, opts ...WaitOption) (err error)
Wait runs a given work function under a context with a particular backoff algorithm if the work needs to be retried.
Each time the work is attempted, this function sets its return value to the error produced by the work. If the context expires and the work has not returned an error, the context error is returned instead.
Types ¶
type WaitOption ¶
type WaitOption interface { // ApplyToWaitOptions configures the specified wait options for this option. ApplyToWaitOptions(target *WaitOptions) }
WaitOption is a setter for one or more wait options.
func WithBackoffFactory ¶
func WithBackoffFactory(bf *backoff.Factory) WaitOption
WithBackoffFactory changes the backoff algorithm to the specified one.
func WithClock ¶
func WithClock(c clock.Clock) WaitOption
WithClock changes the backoff clock to the specified one.
type WaitOptionFunc ¶
type WaitOptionFunc func(target *WaitOptions)
WaitOptionFunc allows a function to be used as a wait option.
func (WaitOptionFunc) ApplyToWaitOptions ¶
func (wof WaitOptionFunc) ApplyToWaitOptions(target *WaitOptions)
ApplyToWaitOptions configures the specified wait options by calling this function.
type WaitOptions ¶
type WaitOptions struct { // BackoffFactory is the backoff algorithm to use for waiting. If not // specified, a sensible default appropriate for network communication will // be chosen: a non-sliding exponential backoff with factor 2 and full // jitter. BackoffFactory *backoff.Factory // Clock is the clock implementation used to perform the backoff. Clock clock.Clock }
WaitOptions allows the behavior of Wait to be customized.
func (*WaitOptions) ApplyOptions ¶
func (o *WaitOptions) ApplyOptions(opts []WaitOption)
ApplyOptions runs each of the given options against this options struct.