Documentation
¶
Overview ¶
Package backoff provides pluggable retry delay strategies for job execution. All strategies are safe for concurrent use (they are stateless).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Constant ¶
Constant always returns the same delay regardless of attempt number.
func NewConstant ¶
NewConstant creates a constant backoff strategy.
type Exponential ¶
Exponential doubles the delay each attempt. Delay = min(Initial * 2^(attempt-1), Max).
func NewExponential ¶
func NewExponential(initial, maxDelay time.Duration) *Exponential
NewExponential creates an exponential backoff strategy.
type ExponentialWithJitter ¶
ExponentialWithJitter applies full jitter to an exponential base. Delay = random value in [0, min(Initial * 2^(attempt-1), Max)]. This prevents thundering herd when many retries happen simultaneously.
func NewExponentialWithJitter ¶
func NewExponentialWithJitter(initial, maxDelay time.Duration) *ExponentialWithJitter
NewExponentialWithJitter creates an exponential backoff with full jitter.
type Linear ¶
Linear increases the delay linearly with the attempt number. Delay = min(Initial * attempt, Max).
type Strategy ¶
type Strategy interface {
// Delay returns how long to wait before retry attempt n (1-indexed).
// Attempt 1 is the first retry after the initial failure.
Delay(attempt int) time.Duration
}
Strategy computes the delay before a retry attempt.
func DefaultStrategy ¶
func DefaultStrategy() Strategy
DefaultStrategy returns the default backoff used by the engine: ExponentialWithJitter with 1s initial and 1m max.