Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BackoffStrategy ¶
type BackoffStrategy struct {
// contains filtered or unexported fields
}
BackoffStrategy describes the behaviour of backing off upon errors.
func NewBackoffStrategy ¶
func NewBackoffStrategy(generator Generator, durationUnit time.Duration) BackoffStrategy
NewBackoffStrategy is a constructor for BackoffStrategy. It accepts Generator, which is responsible for generating the backoff sequence, and time.Duration, which is a duration of one step/iteration (this duration will be multiplied by numbers from the sequence, generated by Generator).
func (BackoffStrategy) Delay ¶
func (b BackoffStrategy) Delay() (time.Duration, error)
Delay is the main method that upon each subsequent execution, returns the next delay for this strategy.
func (BackoffStrategy) WithCappedDuration ¶
func (b BackoffStrategy) WithCappedDuration(cappedDuration time.Duration) BackoffStrategy
WithCappedDuration adds a possibility to specify a cap for the duration, i.e. the highest value that will never be exceeded.
func (BackoffStrategy) WithJitter ¶
func (b BackoffStrategy) WithJitter(jitter time.Duration) BackoffStrategy
WithJitter adds a possibility to add some randomized variation to the delays: +- some duration, less than `jitter` parameter.
func (BackoffStrategy) WithMaxRetries ¶
func (b BackoffStrategy) WithMaxRetries(maxRetries int64) BackoffStrategy
WithMaxRetries adds a possibility to specify the max number of retries for this strategy.
type Caller ¶
type Caller struct {
// contains filtered or unexported fields
}
Caller is the main type of the library, responsible for calling a specified function, following the specified retry strategy.
func (Caller) Call ¶
Call is the main method that accepts a context.Context (which can be used to terminate retrying) and the function, which is essentially a wrapper around some actual function.
func (Caller) WithMaxDuration ¶
WithMaxDuration allow one to specify maximum duration (total for all retries).
func (Caller) WithRetriableError ¶
func (c Caller) WithRetriableError(err error, strategy BackoffStrategy) Caller
WithRetriableError allows one to register an error along with the backoff strategy for it.
func (Caller) WithRetryOnAnyError ¶
func (c Caller) WithRetryOnAnyError(strategy BackoffStrategy) Caller
WithRetryOnAnyError acts like WithRetriableError, but the specified strategy will be used upon getting _any_ error ( i.e. it makes all errors retriable).
type Generator ¶
type Generator interface { // Next method returns a next number in the sequence. Next() int64 }
Generator interface describes an abstraction for implementing sequence generators (used in the back-off strategy).
func NewConstant ¶
NewConstant creates a Generator that always return the same number (specified as `c` parameter).
func NewExponential ¶
NewExponential creates a Generator where every next number is the previous number multiplied by some `factor` (starts with 0).
func NewFibonacci ¶
func NewFibonacci() Generator
NewFibonacci creates a Generator where every next number is a sum of two previous numbers (Fibonacci sequence). Starts with 1.