retry

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 16, 2023 License: Apache-2.0 Imports: 6 Imported by: 15

Documentation

Overview

Package retry allows operations to be retried if they fail transiently. Retries are typically paired with a backoff algorithm.

Index

Constants

This section is empty.

Variables

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 Done added in v0.4.0

func Done(err error) (bool, error)

Done indicates that work should not be retried.

func DoneUnlessMarkedTransient added in v0.4.0

func DoneUnlessMarkedTransient(err error) (bool, error)

DoneUnlessMarkedTransient indicates that work should not be retried unless the given error is marked transient.

func Repeat added in v0.4.0

func Repeat(err error) (bool, error)

Repeat indicates that work should be retried.

func RepeatUnlessMarkedUser added in v0.4.0

func RepeatUnlessMarkedUser(err error) (bool, error)

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.

func WaitAsync

func WaitAsync(ctx context.Context, work WorkFunc, opts ...WaitOption) <-chan error

WaitAsync runs a given work function in a separate Goroutine, but otherwise behaves identically to Wait.

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.

type WorkFunc

type WorkFunc func(ctx context.Context) (bool, error)

WorkFunc is a function that performs an arbitrary operation. If the operation needs to be retried for any reason, the function must return false.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL