retry

package
v0.27.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do(fn DoFunc, opts ...Option) error

Do will retry the given DoFunc until it or an option returns false. The last returned error value (can be nil) of fn will be returned.

func DoTemporaryError

func DoTemporaryError(fn DoTempFunc, opts ...Option) error

DoTemporaryError will retry as long as the error returned from fn is temporary as defined by IsTemporaryError.

func IsTemporaryError

func IsTemporaryError(err error) bool

IsTemporaryError will determine if an error is temporary, and thus the action can/should be retried.

Types

type DoFunc

type DoFunc func(int) (bool, error)

DoFunc is a function that can be retried. It is passed the current attempt number (starting with 0) and should return true if a retry should be attempted.

type DoTempFunc

type DoTempFunc func(int) error

DoTempFunc is a simplified version of DoFunc that just returns an error value.

type Option

type Option func(int, error) bool

An Option takes the attempt number and the last error value (can be nil) and should indicate if a retry should be made.

func Context added in v0.24.0

func Context(ctx context.Context) Option

Context will allow retry to continue until the context is cancelled.

func FibBackoff

func FibBackoff(d time.Duration) Option

FibBackoff will Sleep for f(n) * Duration (+/- 50ms) before each attempt, where f(n) is the value from the Fibonacci sequence for the nth attempt. There is no delay for the first attempt (n=0).

func Limit

func Limit(n int) Option

Limit will set the max number of retry attempts (including the initial attempt).

func Log

func Log(ctx context.Context) Option

Log will log all errors between retries returned from the DoFunc. The final error, if any, is not logged.

Jump to

Keyboard shortcuts

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