retry

package
v0.0.0-...-f0e227c Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

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.

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 OnErrorFunc

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

OnErrorFunc is called if an 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 {
	// Timeout lets WithBackoff give up once elapsed (if >0).
	Timeout time.Duration
	// OnError is called if an error occurs.
	OnError OnErrorFunc
	// OnSuccess is called once the operation succeeds.
	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