Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Backoff ¶
type Backoff interface { // Mark the next call to NextInterval as the "first" retry in a sequence. // If the generated intervals are dependent on the number of consecutive // (unsuccessful) retries, previous retries should be forgotten here. Reset() // Generate the next backoff interval. NextInterval() time.Duration // Clone creates a copy of the backoff with a nil-internal state. This // allows a backoff object to be used as a prototype factory. Clone() Backoff }
Backoff is the interface to a backoff interval generator.
func NewConstantBackoff ¶
NewConstantBackoff creates a backoff interval generator which always returns the same interval.
func NewExponentialBackoff ¶
func NewExponentialBackoff(minInterval, maxInterval time.Duration, configs ...ExponentialConfigFunc) Backoff
NewExponentialBackoff creates an exponential backoff interval generator using the given minimum and maximum interval. The base interval is given by the following function where n is the number of previous failed attempts in the current sequence.
`MinInterval * Multiplier ^ n`
The value returned on each update is given by the following, where base is the value calculated above. A random factor of zero makes the generator deterministic. Some random jitter tends to work well in practice to avoid issues around a thundering herd.
`min(MaxInterval, base +/- (base * RandFactor))`.
func NewLinearBackoff ¶
NewLinearBackoff creates a backoff interval generator which increases by a constant amount on each unsuccessful retry.
func NewZeroBackoff ¶
func NewZeroBackoff() Backoff
NewZeroBackoff creates a backoff interval generator which always returns a zero interval.
type ExponentialConfigFunc ¶
type ExponentialConfigFunc func(*exponentialBackoff)
ExponentialConfigFunc is a function used to initialize a new exponential backoff.
func WithMultiplier ¶
func WithMultiplier(multiplier float64) ExponentialConfigFunc
WithMultiplier sets the base of the exponential function (default is 2).
func WithRandomFactor ¶
func WithRandomFactor(randFactor float64) ExponentialConfigFunc
WithRandomFactor sets the random factor (default is 0, no randomness).