retry

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2021 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultInitialInterval = 500 * time.Millisecond
	DefaultMaxRetries      = 100
	DefaultMaxInterval     = 60 * time.Second

	DefaultMultiplier          float64 = 1.5
	DefaultRandomizationFactor float64 = 0.5
)

Retry constants

View Source
const (
	CannotBeRetried    = "this operation cannot be retried"
	MaxRetriesExceeded = "this operation exceeded the maximum number of retries"
	MaxElapsedExceeded = "this operation exceeded the maximum time allowed to complete"
)

Error constant texts

Variables

This section is empty.

Functions

func DoNotRetry

func DoNotRetry(err error) error

DoNotRetry wraps an error with ErrDoNotRetry so that it won't be retried by a Retryer

Types

type Backoff

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

Backoff is a configurable retry backoff strategy

func NewBackoff

func NewBackoff(options ...BackoffOption) *Backoff

NewBackoff constructs a new Backoff

func NewConstantBackoff

func NewConstantBackoff(options ...BackoffOption) *Backoff

NewConstantBackoff constructs a Backoff strategy with a constant backoff retry rate

func NewExponentialBackoff

func NewExponentialBackoff(options ...BackoffOption) *Backoff

NewExponentialBackoff constructs a Backoff strategy with a exponential backoff retry rate

func (Backoff) Retry

func (b Backoff) Retry(ctx context.Context, fn func() error) error

Retry executes a command until it succeeds, encounters an ErrDoNotRetry error, or reaches the backoff strategy limits

type BackoffOption

type BackoffOption func(*Backoff)

BackoffOption options for Backoff

func WithBackoffInitialInterval

func WithBackoffInitialInterval(initialInterval time.Duration) BackoffOption

WithBackoffInitialInterval sets the initialInterval for Backoff

func WithBackoffMaxInterval

func WithBackoffMaxInterval(maxInterval time.Duration) BackoffOption

WithBackoffMaxInterval sets the maximum interval duration for Backoff

func WithBackoffMaxRetries

func WithBackoffMaxRetries(maxRetries int) BackoffOption

WithBackoffMaxRetries sets the maximum number of retries for Backoff

func WithBackoffMultiplier

func WithBackoffMultiplier(multiplier float64) BackoffOption

WithBackoffMultiplier sets the interval duration multipler for Backoff

func WithBackoffRandomizationFactor

func WithBackoffRandomizationFactor(randomizationFactor float64) BackoffOption

WithBackoffRandomizationFactor sets the randomization factor (min and max jigger) for Backoff

type ErrDoNotRetry

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

ErrDoNotRetry is used to wrap errors from retried calls that shouldn't be retried

func (*ErrDoNotRetry) Error

func (e *ErrDoNotRetry) Error() string

func (*ErrDoNotRetry) Unwrap

func (e *ErrDoNotRetry) Unwrap() error

type Retryer

type Retryer interface {
	Retry(ctx context.Context, fn func() error) error
}

Retryer interface

Jump to

Keyboard shortcuts

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