retry

package
v0.8.2 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2025 License: MIT Imports: 11 Imported by: 5

Documentation

Index

Constants

View Source
const DefaultTimeout = 5 * time.Minute

DefaultTimeout is our opinionated default timeout for retrying database and Redis operations.

Variables

This section is empty.

Functions

func Retryable

func Retryable(err error) bool

Retryable returns true for common errors that are considered retryable, i.e. temporary, timeout, DNS, connection refused and reset, host down and unreachable and network down and unreachable errors. In addition, any database error is considered retryable.

func WithBackoff

func WithBackoff(
	ctx context.Context, retryableFunc RetryableFunc, retryable IsRetryable, b backoff.Backoff, settings Settings,
) (err error)

WithBackoff retries the passed function if it fails and the error allows it to retry. The specified backoff policy is used to determine how long to sleep between attempts.

Types

type IsRetryable

type IsRetryable func(error) bool

IsRetryable checks whether a new attempt can be started based on the error passed.

type OnRetryableErrorFunc

type OnRetryableErrorFunc func(elapsed time.Duration, attempt uint64, err, lastErr error)

OnRetryableErrorFunc is called if a retryable error occurs.

type OnSuccessFunc

type OnSuccessFunc func(elapsed time.Duration, attempt uint64, lastErr error)

OnSuccessFunc is called once the operation succeeds.

type RetryableFunc

type RetryableFunc func(context.Context) error

RetryableFunc is a retryable function.

type Settings

type Settings struct {
	// If >0, Timeout lets WithBackoff stop retrying gracefully once elapsed based on the following criteria:
	// * If the execution of RetryableFunc has taken longer than Timeout, no further attempts are made.
	// * If Timeout elapses during the sleep phase between retries, one final retry is attempted.
	// * RetryableFunc is always granted its full execution time and is not canceled if it exceeds Timeout.
	// This means that WithBackoff may not stop exactly after Timeout expires,
	// or may not retry at all if the first execution of RetryableFunc already takes longer than Timeout.
	Timeout          time.Duration
	OnRetryableError OnRetryableErrorFunc
	OnSuccess        OnSuccessFunc
}

Settings aggregates optional settings for WithBackoff.

Jump to

Keyboard shortcuts

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