Documentation
¶
Overview ¶
Package retry provides retry logic with exponential backoff and jitter.
The retry strategy uses exponential backoff where each successive retry waits longer, with random jitter to prevent thundering herd problems when many clients retry simultaneously.
Index ¶
Constants ¶
const ( // DefaultMaxRetries is the default maximum number of retry attempts. DefaultMaxRetries = 3 // DefaultBaseDelay is the default initial delay between retries. DefaultBaseDelay = 100 * time.Millisecond // DefaultMaxDelay is the default maximum delay between retries. DefaultMaxDelay = 10 * time.Second )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// MaxRetries is the maximum number of retry attempts after the initial
// request fails. Set to 0 to disable retries.
MaxRetries int
// BaseDelay is the initial delay before the first retry.
// Subsequent retries double this delay up to MaxDelay.
BaseDelay time.Duration
// MaxDelay caps the maximum delay between retries.
MaxDelay time.Duration
}
Config controls retry behavior.
type Retryer ¶
type Retryer struct {
// contains filtered or unexported fields
}
Retryer calculates retry delays using exponential backoff with jitter.
func New ¶
New creates a Retryer with the given configuration. Invalid or zero values are replaced with defaults.
func (*Retryer) Backoff ¶
Backoff calculates the delay before the given attempt. Attempt 0 (initial request) returns 0. Subsequent attempts return exponentially increasing delays with ±25% random jitter.
func (*Retryer) MaxAttempts ¶
MaxAttempts returns the total number of attempts including the initial request.