Documentation
¶
Overview ¶
Package backoff provides backoff mechanisms for retrying operations.
Index ¶
Constants ¶
const ( MinDelay = 20 * time.Millisecond MaxDelay = 10 * time.Second ErrUnknownScale = consterr.Error("unknown scale") ErrInvalidScale = consterr.Error("invalid scale") )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Base ¶
type Base struct {
// contains filtered or unexported fields
}
Base is a base entity suitable for most backoff implementations. It is expected to be embedded, not to be used directly.
type ExponentialJitter ¶
type ExponentialJitter struct {
Base
}
ExponentialJitter is an implementation of Backoff interface that provides backoff delays with jitter. Delay grows exponentially.
func NewExponentialJitter ¶
func NewExponentialJitter(base, limit time.Duration, options ...Option) ExponentialJitter
NewExponentialJitter returns a configured ExponentialJitter. Arguments are the same as for NewBase.
func (ExponentialJitter) RetryDelay ¶
func (b ExponentialJitter) RetryDelay(attempt int) time.Duration
RetryDelay returns delay before next retry based on the attempt number. Formula is: min(exponentialBase^attempt * baseDelay * (1 + [0.0..1.0)/2), maxDelay).
type Func ¶
Func is an implementation of Backoff interface suitable for simple scenarios.
type LinearJitter ¶
type LinearJitter struct {
Base
}
LinearJitter is an implementation of Backoff interface that provides backoff delays with jitter. Delay grows linearly.
func NewLinearJitter ¶
func NewLinearJitter(base, limit time.Duration, options ...Option) LinearJitter
NewLinearJitter returns a configured LinearJitter. Arguments are the same as for NewBase.
func (LinearJitter) RetryDelay ¶
func (b LinearJitter) RetryDelay(attempt int) time.Duration
RetryDelay returns delay before next retry based on the attempt number. Formula is: min((attempt + 1) * baseDelay * (1 + [0.0..1.0)/2), maxDelay).
type Option ¶
type Option func(*Base)
Option is a functional option type that extends Base functionality
type ProgressiveJitter ¶
type ProgressiveJitter struct {
Base
}
ProgressiveJitter is an implementation of Backoff interface that provides backoff delays with jitter. Delay grows in progression.
func NewProgressiveJitter ¶
func NewProgressiveJitter(base, limit time.Duration, options ...Option) ProgressiveJitter
NewProgressiveJitter returns a configured ProgressiveJitter. Arguments are the same as for NewBase. Using base value of 1ms is not recommended, see RetryDelay.
func (ProgressiveJitter) RetryDelay ¶
func (b ProgressiveJitter) RetryDelay(attempt int) time.Duration
RetryDelay returns delay before next retry based on the attempt number. Formula is: min((baseDelay/ms)^(attempt + 1) * (1 + [0.0..1.0)/2) * ms, maxDelay).