retry

package
v0.0.0-...-44a576d Latest Latest
Warning

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

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

Documentation

Overview

Package retry provides configurable retry strategies with exponential backoff, jitter, and context-aware cancellation for the ResolveAgent platform. It integrates with the feedback loop to emit retry outcome signals.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

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

Do executes fn with the retry policy. It returns the first nil error or the last error after all attempts are exhausted. When an Observer is set on the policy, it emits success/exhausted signals to close the retry feedback loop.

Types

type Policy

type Policy struct {
	// MaxAttempts is the total number of attempts (including the first call).
	MaxAttempts int
	// InitialDelay is the delay before the first retry.
	InitialDelay time.Duration
	// MaxDelay caps the backoff delay.
	MaxDelay time.Duration
	// Multiplier is the backoff multiplier (default 2.0).
	Multiplier float64
	// Jitter adds random jitter up to this fraction of the delay (0.0–1.0).
	Jitter float64
	// RetryIf is an optional predicate; if set, only retry when it returns true.
	RetryIf func(err error) bool
	// Observer receives retry lifecycle events for feedback loop integration.
	Observer RetryObserver
}

Policy defines retry behavior.

func DefaultPolicy

func DefaultPolicy() Policy

DefaultPolicy returns a sensible default retry policy.

type RetryObserver

type RetryObserver interface {
	// OnRetrySuccess is called when the operation succeeds after retries.
	OnRetrySuccess(ctx context.Context, attempts int, totalDuration time.Duration)
	// OnRetryExhausted is called when all retry attempts are exhausted.
	OnRetryExhausted(ctx context.Context, attempts int, totalDuration time.Duration, lastErr error)
}

RetryObserver receives lifecycle events from the retry loop, enabling the feedback subsystem to track retry outcomes.

Jump to

Keyboard shortcuts

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