retry

package
v1.206.3-rc.2 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrMaxAttemptsMustBePositive    = errors.New("max_attempts must be greater than zero")
	ErrMaxElapsedTimeMustBePositive = errors.New("max_elapsed_time must be greater than zero")
	ErrMultiplierMustBePositive     = errors.New("multiplier must be greater than zero")
	ErrMaxDelayMustBePositive       = errors.New("max_delay must be greater than zero")
	ErrInitialDelayCannotBeNegative = errors.New("initial_delay cannot be negative")
	ErrRandomJitterOutOfRange       = errors.New("random_jitter must be between 0.0 and 1.0")
)

Validation errors.

View Source
var UnexpectedError = errors.New("unexpected end of retry loop")

UnexpectedError is returned when the retry loop ends unexpectedly.

Functions

func DefaultConfig

func DefaultConfig() schema.RetryConfig

DefaultConfig returns a sensible default configuration for a single attempt. Most fields are nil (disabled/unlimited).

func Do

func Do(ctx context.Context, config *schema.RetryConfig, fn Func) error

Do is a convenience function that creates an executor and runs the function. If config is nil, a default single-attempt config is used to ensure consistent error messages (e.g., "max attempts (1) exceeded, last error: ...").

func Validate

func Validate(config *schema.RetryConfig) error

Validate checks that explicitly set values are valid. Returns an error if any field is explicitly set to an invalid value (e.g., zero or negative). Nil values are valid and mean "disabled" or "unlimited".

func With7Params

func With7Params[T1 any, T2 any, T3 any, T4 any, T5 any, T6 any, T7 any](ctx context.Context,
	config *schema.RetryConfig,
	fn func(T1, T2, T3, T4, T5, T6, T7) error, a T1, b T2, c T3, d T4, e T5, f T6, g T7,
) error

With7Params is a convenience function for retrying functions with 7 parameters.

func WithPredicate

func WithPredicate(ctx context.Context, config *schema.RetryConfig, fn Func, shouldRetry func(error) bool) error

WithPredicate allows you to specify which errors should trigger a retry. If config is nil, the function is executed once without retry.

Types

type Executor

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

Executor handles the retry logic.

func New

func New(config schema.RetryConfig) *Executor

New creates a new retry executor with the given config.

func (*Executor) Execute

func (e *Executor) Execute(ctx context.Context, fn Func) error

Execute runs the function with retry logic.

func (*Executor) ExecuteWithPredicate

func (e *Executor) ExecuteWithPredicate(ctx context.Context, fn Func, shouldRetry func(error) bool) error

ExecuteWithPredicate runs the function with retry logic, using the predicate to determine if an error should trigger a retry.

type Func

type Func func() error

Func represents a function that can be retried.

type MaxElapsedTimeError

type MaxElapsedTimeError struct {
	MaxElapsedTime time.Duration
}

MaxElapsedTimeError is returned when the retry timeout is exceeded.

func (MaxElapsedTimeError) Error

func (e MaxElapsedTimeError) Error() string

Jump to

Keyboard shortcuts

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