retry

package
v0.0.0-...-1929ff6 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package retry provides a generic retry mechanism with exponential backoff.

Example:

ctx := context.Background()
client := foobar.NewClient()

err := retry.Do(func() error {
	err := client.UpdateConfig(ctx, map[string]any{"key": "value"})

	// will be retied
	if errors.Is(err, foobar.ErrTxConflict) {
		return retry.Retryable(err)
	}

	return err
})

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do

func Do(cb Callback) error

Do executes the callback function with the default backoff config. It will retry a callback ONLY if error is retryable.

func DoTyped

func DoTyped[T any](cb TypedCallback[T]) (T, error)

DoTyped is typed version of Do that returns a value along with an error. It will retry a callback ONLY if error is retryable.

func DoTypedWithBackoff

func DoTypedWithBackoff[T any](cb TypedCallback[T], bo Backoff) (T, error)

DoTypedWithBackoff is typed version of DoWithBackoff that returns a value along with an error. It will retry a callback ONLY if error is retryable.

func DoTypedWithBackoffAndRetry

func DoTypedWithBackoffAndRetry[T any](cb TypedCallback[T], bo Backoff) (T, error)

DoTypedWithBackoffAndRetry is DoTypedWithBackoff but ANY error is retried.

func DoTypedWithRetry

func DoTypedWithRetry[T any](cb TypedCallback[T]) (T, error)

DoTypedWithRetry is DoTyped but ANY error is retried.

func DoWithBackoff

func DoWithBackoff(cb Callback, bo Backoff) error

DoWithBackoff executes the callback function with provided backoff config. It will retry a callback ONLY if error is retryable.

func Retry

func Retry(err error) error

Retry wraps error to mark it as retryable. Skips retry for context errors.

func RetryTyped

func RetryTyped[T any](result T, err error) (T, error)

RetryTyped wraps error to mark it as retryable

Types

type Backoff

type Backoff = backoff.BackOff

func DefaultBackoff

func DefaultBackoff() Backoff

DefaultBackoff returns a default backoff strategy with 5 exponential retries.

func DefaultConstantBackoff

func DefaultConstantBackoff() Backoff

type Callback

type Callback func() error

type TypedCallback

type TypedCallback[T any] func() (T, error)

Jump to

Keyboard shortcuts

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