retry

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package retry is a retry with backoff implementation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddJitter

func AddJitter(duration time.Duration, jitter time.Duration) time.Duration

AddJitter adds an amount of jitter between 0 and the given jitter to the given duration

func NWithBackoff

func NWithBackoff(backoff Backoff, n int, fn func() error) error

NWithBackoff takes a Backoff, a maximum number of tries 'n', and a function that returns an error. The function is called until either it does not return an error or the maximum tries have been reached. If the error returned is Retriable, the Retriability of it will be respected. If the number of tries is exhausted, the last error will be returned.

func NWithBackoffCtx

func NWithBackoffCtx(ctx context.Context, backoff Backoff, n int, fn func() error) error

NWithBackoffCtx takes a context, a Backoff, a maximum number of tries 'n', and a function that returns an error. The function is called until it does not return an error, the context is done, or the maximum tries have been reached. If the error returned is Retriable, the Retriability of it will be respected. If the number of tries is exhausted, the last error will be returned.

func WithBackoff

func WithBackoff(backoff Backoff, fn func() error) error

WithBackoff takes a Backoff and a function to call that returns an error If the error is nil then the function will no longer be called If the error is Retriable then that will be used to determine if it should be retried

func WithBackoffCtx

func WithBackoffCtx(ctx context.Context, backoff Backoff, fn func() error) error

WithBackoffCtx takes a context, a Backoff, and a function to call that returns an error If the context is done, nil will be returned If the error is nil then the function will no longer be called If the error is Retriable then that will be used to determine if it should be retried

Types

type Backoff

type Backoff interface {
	Reset()
	Duration() time.Duration
}

Backoff is the backoff interface

type DefaultRetriable

type DefaultRetriable struct {
	// contains filtered or unexported fields
}

DefaultRetriable is the default retryable

func (DefaultRetriable) Retry

func (dr DefaultRetriable) Retry() bool

Retry does the retry

type DefaultRetriableError

type DefaultRetriableError struct {
	Retriable
	// contains filtered or unexported fields
}

DefaultRetriableError is the default retriable error

type Retriable

type Retriable interface {
	Retry() bool
}

Retriable is the retry interface

func NewRetriable

func NewRetriable(retry bool) Retriable

NewRetriable creates a new Retriable

type RetriableError

type RetriableError interface {
	Retriable
	error
}

RetriableError interface

func NewRetriableError

func NewRetriableError(retriable Retriable, err error) RetriableError

NewRetriableError returns a new retriable error

type SimpleBackoff

type SimpleBackoff struct {
	// contains filtered or unexported fields
}

SimpleBackoff is the default simple backoff

func NewSimpleBackoff

func NewSimpleBackoff(min, max time.Duration, jitterMultiple, multiple float64) *SimpleBackoff

NewSimpleBackoff creates a Backoff which ranges from min to max increasing by multiple each time. It also adds (and yes, the jitter is always added, never subtracted) a random amount of jitter up to jitterMultiple percent (that is, jitterMultiple = 0.0 is no jitter, 0.15 is 15% added jitter). The total time/ may exceed "max" when accounting for jitter, such that the absolute max is max + max * jitterMultiple

func (*SimpleBackoff) Duration

func (sb *SimpleBackoff) Duration() time.Duration

Duration gets the current duration including jitter

func (*SimpleBackoff) Reset

func (sb *SimpleBackoff) Reset()

Reset resets the backoff

Jump to

Keyboard shortcuts

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