retry

package
v1.13.0 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2026 License: Apache-2.0 Imports: 5 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do(ctx context.Context, cfg Config, op string, fn Operation) error

Do executes an operation with exponential backoff retry for retryable errors

func DoWithKey

func DoWithKey(ctx context.Context, cfg Config, op string, key string, fn Operation) error

DoWithKey executes an operation with exponential backoff retry for retryable errors, including key information for better logging

Types

type Backoff

type Backoff struct {
	// contains filtered or unexported fields
}

Backoff provides a simple backoff iterator for custom retry loops

func NewBackoff

func NewBackoff(cfg Config) *Backoff

NewBackoff creates a new backoff iterator

func (*Backoff) Attempts

func (b *Backoff) Attempts() int

Attempts returns the number of attempts made

func (*Backoff) Next

func (b *Backoff) Next() (time.Duration, bool)

Next returns the next backoff delay and whether to continue retrying

func (*Backoff) Reset

func (b *Backoff) Reset()

Reset resets the backoff to initial state

type Config

type Config struct {
	InitialDelay time.Duration // Initial delay before first retry
	MaxDelay     time.Duration // Maximum delay between retries
	MaxRetries   int           // Maximum number of retry attempts
	Multiplier   float64       // Backoff multiplier
	JitterFactor float64       // Jitter factor (0.0 to 1.0)
}

Config holds retry configuration

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default retry configuration

func FastConfig

func FastConfig() Config

FastConfig returns a configuration for fast retries (used for lock conflicts)

type Operation

type Operation func() error

Operation represents a retryable operation

type RetryableReader

type RetryableReader struct {
	// contains filtered or unexported fields
}

RetryableReader wraps an io.Reader to add retry capability for read operations

func NewRetryableReader

func NewRetryableReader(ctx context.Context, cfg Config, op, key string, reader func() ([]byte, error)) *RetryableReader

NewRetryableReader creates a new retryable reader

func (*RetryableReader) Read

func (r *RetryableReader) Read(p []byte) (n int, err error)

Read implements io.Reader with retry logic

Jump to

Keyboard shortcuts

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