retry

package
v1.17.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 28, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL