Documentation
¶
Overview ¶
Package retry provides exponential backoff retry mechanisms for high availability.
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrMaxAttemptsExceeded = errors.New("maximum retry attempts exceeded") ErrContextCanceled = errors.New("context canceled") )
Retryable errors
View Source
var Retryable = func(err error) bool {
return isTemporary(err) || isTimeout(err)
}
Retryable wraps common errors that should be retried.
Functions ¶
Types ¶
type Config ¶
type Config struct {
// MaxAttempts is the maximum number of retry attempts.
// 0 means unlimited retries (use with caution).
// Default: 3
MaxAttempts int
// InitialDelay is the initial delay before first retry.
// Default: 100ms
InitialDelay time.Duration
// MaxDelay is the maximum delay between retries.
// Default: 30s
MaxDelay time.Duration
// Multiplier is the factor by which delay is multiplied after each attempt.
// Default: 2.0
Multiplier float64
// Jitter adds randomness to prevent thundering herd.
// 0 means no jitter, 1 means full jitter.
// Default: 0.1
Jitter float64
// RetryableError determines if an error is retryable.
// If nil, all errors are retryable.
RetryableError func(error) bool
}
Config holds retry configuration.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns a Config with sensible defaults.
type Retrier ¶
type Retrier struct {
// contains filtered or unexported fields
}
Retrier implements retry with exponential backoff.
func NewRetrier ¶
NewRetrier creates a new retrier with the given configuration.
func WithMaxAttempts ¶
WithMaxAttempts creates a new retrier with the specified max attempts.
func WithRetryableError ¶
WithRetryableError creates a new retrier with a custom retryable error function.
Click to show internal directories.
Click to hide internal directories.