Documentation
¶
Overview ¶
Package retry provides a generic retry utility with exponential backoff and jitter for transient network failures.
Index ¶
Constants ¶
View Source
const ComponentRetry = "retry"
ComponentRetry is the log component name for retry operations.
Variables ¶
This section is empty.
Functions ¶
func Do ¶
func Do(ctx context.Context, cfg Config, operation string, fn func(ctx context.Context) error) error
Do executes fn, retrying on transient errors with exponential backoff and jitter. It respects context cancellation and logs each retry attempt. Returns the last error if all attempts are exhausted.
func IsTransient ¶
IsTransient returns true for errors that are typically transient network failures worth retrying: timeouts, DNS errors, connection refused, and connection reset.
Types ¶
type Config ¶
type Config struct {
// MaxAttempts is the total number of attempts (initial + retries).
// A value of 1 means no retries. Zero defaults to 3.
MaxAttempts int
// InitialDelay is the base delay before the first retry.
// Zero defaults to 1 second.
InitialDelay time.Duration
// MaxDelay caps the backoff delay. Zero defaults to 30 seconds.
MaxDelay time.Duration
// Multiplier scales the delay between retries. Zero defaults to 2.0.
Multiplier float64
// IsRetryable determines whether an error should be retried.
// If nil, the default transient error classifier is used.
IsRetryable func(error) bool
}
Config controls retry behavior.
Click to show internal directories.
Click to hide internal directories.