Documentation
¶
Overview ¶
Package retry provides context-aware retry-with-backoff utilities.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithBackoff ¶
func WithBackoff(ctx context.Context, cfg Config, logger *log.Logger, caller string, fn func() error) error
WithBackoff retries fn with exponential backoff, honouring ctx cancellation during sleep intervals. The caller label is used in log messages. Returns the last error from fn if all attempts fail, or nil on success. If ctx is cancelled during a backoff sleep, ctx.Err() is returned immediately.
Types ¶
type Config ¶
type Config struct {
// MaxRetries is the maximum number of retry attempts (not counting the
// initial call). The total number of calls to fn is MaxRetries+1.
MaxRetries int
// InitialBackoff is the delay before the first retry; it doubles on each
// consecutive failure up to MaxBackoff.
InitialBackoff time.Duration
// MaxBackoff caps the exponential backoff delay.
MaxBackoff time.Duration
}
Config controls the parameters for WithBackoff.
Click to show internal directories.
Click to hide internal directories.