retryx

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package retryx classifies transient failures and retries operations with bounded, jittered exponential backoff.

The classification is deliberately conservative: an error is retried only when repeating the request could plausibly succeed. Authentication failures, missing blobs, permission problems and a full disk are all permanent, and retrying them only delays the report the user needs.

Index

Constants

This section is empty.

Variables

View Source
var Default = Policy{MaxAttempts: 6, BaseDelay: 300 * time.Millisecond, MaxDelay: 30 * time.Second}

Default is the policy used when the user does not override it.

View Source
var ErrRetryable = errors.New("retryable")

ErrRetryable marks an error as worth another attempt when the failure is domain knowledge this package does not have — a checksum that did not match, for instance, which says the bytes arrived wrong and may well arrive right the second time.

Functions

func Describe

func Describe(err error) string

Describe returns a short, log-friendly rendering of err. An Azure failure collapses to its status and error code, because the SDK's own message is a multi-line dump of the whole exchange; anything else keeps its own text, which for a filesystem error already names the path.

func Do

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

Do runs fn until it succeeds, returns a permanent error, or runs out of attempts. The error returned is the last one observed, wrapped with the attempt count when more than one attempt was made.

func IsTransient

func IsTransient(err error) bool

IsTransient reports whether err is worth retrying.

func RetryAfter

func RetryAfter(err error) (time.Duration, bool)

RetryAfter extracts a server-supplied delay from an HTTP error response.

func RetryableStatus

func RetryableStatus(code int) bool

RetryableStatus reports whether an HTTP status justifies another attempt. It matches the Azure SDK's own default list, so callers can substitute their own retry predicate without changing behaviour.

Types

type Notify

type Notify func(attempt int, delay time.Duration, err error)

Notify is invoked before sleeping between attempts. attempt is the number of the attempt that just failed, starting at 1.

type Policy

type Policy struct {
	// MaxAttempts counts the first try. 1 disables retrying.
	MaxAttempts int
	BaseDelay   time.Duration
	MaxDelay    time.Duration
}

Policy bounds a retry loop.

Jump to

Keyboard shortcuts

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