Documentation ¶
Overview ¶
Package retry implements a state struct and methods providing exponential backoff as well as a wrapper function that does exponential backoff.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Backoff ¶
type Backoff struct { // If MaxBackoff == MinBackoff the backoff is constant. // If MinBackoff > MaxBackoff, the implementation may generate a runtime panic. MaxBackoff time.Duration MinBackoff time.Duration // Jitter is the maximum value that may be added or substracted based on // the output of a prng. // Jitter should be < 1, and may produce /interesting/ results if it is > 1 or < 0. Jitter float64 // ExpFactor should be > 1, otherwise it will converge to 0. ExpFactor float64 // contains filtered or unexported fields }
Backoff contains the state implementing a generator returning a sequence of intervals to wait.
func DefaultBackoff ¶
func DefaultBackoff() Backoff
DefaultBackoff returns a reasonable default backoff instance.
func (*Backoff) BackoffN ¶
BackoffN is a stateless method that uses the parameters in the receiver to return a backoff interval appropriate for the Nth retry.
type CtxErrors ¶ added in v1.3.0
CtxErrors bundles together Errors and a Ctx error to differentiate the errors that fail due to context expiration errors from errors that exhaust their maximum number of retries.
type Error ¶ added in v1.3.0
type Error struct { // When is when the error occured in the retry cycle. When time.Time // Err is the underlying error. Err error }
Error is an error that occurs at a particular time.
type Errors ¶ added in v1.3.0
type Errors struct {
Errs []*Error
}
Errors is a collection errors that happen across multiple retries.
func (*Errors) As ¶ added in v1.3.0
As will return true if any of the underlying errors matches the target and sets the argument to that error specifically. It returns false otherwise, leaving the argument unchanged. See https://golang.org/pkg/errors/#As
func (*Errors) Is ¶ added in v1.3.0
Is will return true if any of the underlying errors matches the target. See https://golang.org/pkg/errors/#Is
type Retryable ¶
type Retryable struct { // Backoff parameters to use for retry B Backoff // ShouldRetry is a filter function to indicate whether to continue // iterating based on the error. // An implementation that uniformly returns true is used if nil ShouldRetry func(error) bool // Maximum retry attempts MaxSteps int32 // Clock provides a clock to use when backing off (if nil, uses // github.com/vimeo/go-clocks.DefaultClock()) Clock clocks.Clock }
Retryable manages the operations of a retryable operation.
func NewRetryable ¶
NewRetryable returns a newly constructed Retryable instance