Documentation ¶
Overview ¶
Package backoff contains a configurable retry-functionality using either exponential or constant backoff
Index ¶
- Constants
- func NewErrCannotRetry(err error) error
- func Retry(f Retryable) error
- type Backoff
- func (b Backoff) Retry(f Retryable) error
- func (b *Backoff) WithMaxIterationTime(v time.Duration) *Backoff
- func (b *Backoff) WithMaxIterations(v uint64) *Backoff
- func (b *Backoff) WithMaxTotalTime(v time.Duration) *Backoff
- func (b *Backoff) WithMinIterationTime(v time.Duration) *Backoff
- func (b *Backoff) WithMultiplier(v float64) *Backoff
- type ErrCannotRetry
- type Retryable
Constants ¶
const ( // DefaultMaxIterations contains the default value to use for number of iterations: infinite DefaultMaxIterations uint64 = 0 // DefaultMaxIterationTime contains the default value to use for maximum iteration time DefaultMaxIterationTime = 60 * time.Second // DefaultMaxTotalTime contains the default value to use for maximum execution time: infinite DefaultMaxTotalTime time.Duration = 0 // DefaultMinIterationTime contains the default value to use for initial iteration time DefaultMinIterationTime = 100 * time.Millisecond // DefaultMultipler contains the default multiplier to apply to iteration time after each iteration DefaultMultipler float64 = 1.5 )
Variables ¶
This section is empty.
Functions ¶
func NewErrCannotRetry ¶ added in v2.22.0
NewErrCannotRetry wraps the given error into an ErrCannotRetry and should be used to break from a Retry() function when the retry should stop immediately
Types ¶
type Backoff ¶
type Backoff struct { MaxIterations uint64 MaxIterationTime time.Duration MaxTotalTime time.Duration MinIterationTime time.Duration Multiplier float64 }
Backoff holds the configuration for backoff function retries
func NewBackoff ¶
func NewBackoff() *Backoff
NewBackoff creates a new Backoff configuration with default values (see constants)
func (Backoff) Retry ¶
Retry executes the function and waits for it to end successul or for the given limites to be reached. The returned error uses Go1.13 wrapping of errors and can be unwrapped into the error of the function itself.
To break free from the Retry function ignoring the remaining retries return an ErrCannotRetry containing the original error. At this point the ErrCannotRetry will NOT be returned but unwrapped. So returning NewErrCannotRetry(errors.New("foo")) will give you the errors.New("foo") as a return value from Retry.
func (*Backoff) WithMaxIterationTime ¶ added in v2.11.0
WithMaxIterationTime is a wrapper around setting the MaxIterationTime and then returning the Backoff object to use in chained creation
func (*Backoff) WithMaxIterations ¶ added in v2.11.0
WithMaxIterations is a wrapper around setting the MaxIterations and then returning the Backoff object to use in chained creation
func (*Backoff) WithMaxTotalTime ¶ added in v2.11.0
WithMaxTotalTime is a wrapper around setting the MaxTotalTime and then returning the Backoff object to use in chained creation
func (*Backoff) WithMinIterationTime ¶ added in v2.11.0
WithMinIterationTime is a wrapper around setting the MinIterationTime and then returning the Backoff object to use in chained creation
func (*Backoff) WithMultiplier ¶ added in v2.11.0
WithMultiplier is a wrapper around setting the Multiplier and then returning the Backoff object to use in chained creation
type ErrCannotRetry ¶ added in v2.22.0
type ErrCannotRetry struct {
// contains filtered or unexported fields
}
ErrCannotRetry wraps the original error and signals the backoff should be stopped now as a retry i.e. would be harmful or would make no sense
func (ErrCannotRetry) Error ¶ added in v2.22.0
func (e ErrCannotRetry) Error() string
func (ErrCannotRetry) Unwrap ¶ added in v2.22.0
func (e ErrCannotRetry) Unwrap() error