retry

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 6, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package retry retries explicitly classified operations with bounded backoff.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do(ctx context.Context, p Policy, operation func(context.Context) error) error

Do executes the supplied operation with this component's context and policy.

Types

type Metrics

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

Metrics contains optional per-policy cumulative counters; sharing one instance across operations is safe.

func (*Metrics) Snapshot

func (m *Metrics) Snapshot() Snapshot

type Policy

type Policy struct {
	Observer                        instrument.Hook
	Metrics                         *Metrics
	MaxAttempts                     int
	Delay, MaxDelay, MaxElapsed     time.Duration
	Exponential, Jitter, Idempotent bool
	Retryable                       func(error) bool
	OnRetry                         func(int, error, time.Duration)
	DelayFor                        func(int, error, time.Duration) time.Duration
	Clock                           clock.Clock
}

Policy bounds retries and requires explicit idempotency and error classification.

type Snapshot

type Snapshot struct {
	Attempts, Successes, ScheduledRetries, Failures int64
	ScheduledBackoff                                time.Duration
}

Snapshot reports scheduled retries separately from actually executed attempts.

Jump to

Keyboard shortcuts

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