retry

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package retry provides utilities for retrying operations with exponential backoff and classification of transient vs permanent errors.

Index

Constants

View Source
const (
	// DefaultMaxRetries is the default maximum number of retry attempts
	DefaultMaxRetries = 3
	// DefaultInitialDelay is the default initial delay between retries
	DefaultInitialDelay = 100 * time.Millisecond
	// DefaultMaxDelay is the default maximum delay between retries
	DefaultMaxDelay = 10 * time.Second
	// DefaultBackoffFactor is the default exponential backoff factor
	DefaultBackoffFactor = 2.0
	// DefaultJitter is the default jitter factor to add randomness
	DefaultJitter = 0.1
)

Constants for retry configuration

Variables

This section is empty.

Functions

func Do

func Do(ctx context.Context, config Config, operation string, fn RetryFunc) error

Do executes a function with retry logic using exponential backoff

func IsTransientError

func IsTransientError(err error) bool

IsTransientError determines if an error is transient and should be retried

Types

type Config

type Config struct {
	// MaxRetries is the maximum number of retry attempts (excluding the initial attempt)
	MaxRetries int
	// InitialDelay is the initial delay between retries
	InitialDelay time.Duration
	// MaxDelay is the maximum delay between retries
	MaxDelay time.Duration
	// BackoffFactor is the exponential backoff factor
	BackoffFactor float64
	// Jitter adds randomness to delays to avoid thundering herd
	Jitter float64
	// Logger for logging retry attempts
	Logger logr.Logger
	// TestDelay is the delay to add to the retry loop to simulate a test environment
	TestDelay time.Duration
}

Config holds the configuration for retry operations

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a default retry configuration

type RetryFunc

type RetryFunc func() error

RetryFunc is a function that can be retried

type RetryableError

type RetryableError struct {
	Underlying error
	Retryable  bool
	Operation  string
}

RetryableError represents an error that can be retried

func NewRetryableError

func NewRetryableError(err error, retryable bool, operation string) *RetryableError

NewRetryableError creates a new retryable error

func (*RetryableError) Error

func (e *RetryableError) Error() string

func (*RetryableError) Unwrap

func (e *RetryableError) Unwrap() error

Jump to

Keyboard shortcuts

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