retry

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2023 License: MPL-2.0 Imports: 9 Imported by: 20

Documentation

Overview

Package retry provides generic action retry.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExpectedError

func ExpectedError(err error) error

ExpectedError error represents an error that is expected by the retrying function. This error is ignored.

func ExpectedErrorf

func ExpectedErrorf(format string, a ...interface{}) error

ExpectedErrorf makes an expected error from given format and arguments.

func IsTimeout

func IsTimeout(err error) bool

IsTimeout reutrns if the provided error is a timeout error.

func UnexpectedError deprecated

func UnexpectedError(err error) error

UnexpectedError error represents an error that is unexpected by the retrying function. This error is fatal.

Deprecated: all errors are unexpected by default, just return them.

Types

type ConstantTicker

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

ConstantTicker represents a ticker with a constant algorithm.

func NewConstantTicker

func NewConstantTicker(opts *Options) *ConstantTicker

NewConstantTicker is a ticker that sends the time on a channel using a constant algorithm.

func (ConstantTicker) Jitter

func (t ConstantTicker) Jitter() time.Duration

func (ConstantTicker) Stop

func (t ConstantTicker) Stop()

func (ConstantTicker) StopChan

func (t ConstantTicker) StopChan() <-chan struct{}

func (ConstantTicker) Tick

func (c ConstantTicker) Tick() time.Duration

Tick implements the Ticker interface.

type ErrorSet

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

ErrorSet represents a set of unique errors.

func (*ErrorSet) Append

func (e *ErrorSet) Append(err error) bool

Append adds the error to the set if the error is not already present.

func (*ErrorSet) As added in v0.3.3

func (e *ErrorSet) As(target any) bool

As implements errors.As.

func (*ErrorSet) Error

func (e *ErrorSet) Error() string

func (*ErrorSet) Is

func (e *ErrorSet) Is(err error) bool

Is implements errors.Is.

func (*ErrorSet) Unwrap added in v0.3.3

func (e *ErrorSet) Unwrap() []error

Unwrap implements errors.Unwrap.

type ExponentialTicker

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

ExponentialTicker represents a ticker with a truncated exponential algorithm. Please see https://en.wikipedia.org/wiki/Exponential_backoff for details on the algorithm.

func NewExponentialTicker

func NewExponentialTicker(opts *Options) *ExponentialTicker

NewExponentialTicker is a ticker that sends the time on a channel using a truncated exponential algorithm.

func (ExponentialTicker) Jitter

func (t ExponentialTicker) Jitter() time.Duration

func (ExponentialTicker) Stop

func (t ExponentialTicker) Stop()

func (ExponentialTicker) StopChan

func (t ExponentialTicker) StopChan() <-chan struct{}

func (*ExponentialTicker) Tick

func (e *ExponentialTicker) Tick() time.Duration

Tick implements the Ticker interface.

type LinearTicker

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

LinearTicker represents a ticker with a linear algorithm.

func NewLinearTicker

func NewLinearTicker(opts *Options) *LinearTicker

NewLinearTicker is a ticker that sends the time on a channel using a linear algorithm.

func (LinearTicker) Jitter

func (t LinearTicker) Jitter() time.Duration

func (LinearTicker) Stop

func (t LinearTicker) Stop()

func (LinearTicker) StopChan

func (t LinearTicker) StopChan() <-chan struct{}

func (*LinearTicker) Tick

func (l *LinearTicker) Tick() time.Duration

Tick implements the Ticker interface.

type Option

type Option func(*Options)

Option is the functional option func.

func WithAttemptTimeout

func WithAttemptTimeout(o time.Duration) Option

WithAttemptTimeout sets timeout for each retry attempt.

func WithErrorLogging

func WithErrorLogging(enable bool) Option

WithErrorLogging logs errors as they are encountered during the retry loop.

func WithJitter

func WithJitter(o time.Duration) Option

WithJitter is a functional option for setting the jitter flag.

func WithUnits

func WithUnits(o time.Duration) Option

WithUnits is a functional option for setting the units of the ticker.

type Options

type Options struct {
	Units          time.Duration
	Jitter         time.Duration
	AttemptTimeout time.Duration
	LogErrors      bool
}

Options is the functional options struct.

func NewDefaultOptions

func NewDefaultOptions(setters ...Option) *Options

NewDefaultOptions initializes a Options struct with default values.

type RetryableFunc

type RetryableFunc func() error

RetryableFunc represents a function that can be retried.

type RetryableFuncWithContext

type RetryableFuncWithContext func(context.Context) error

RetryableFuncWithContext represents a function that can be retried.

type Retryer

type Retryer interface {
	Retry(RetryableFunc) error
	RetryWithContext(context.Context, RetryableFuncWithContext) error
}

Retryer defines the requirements for retrying a function.

func Constant

func Constant(duration time.Duration, setters ...Option) Retryer

Constant initializes and returns a constant Retryer.

func Exponential

func Exponential(duration time.Duration, setters ...Option) Retryer

Exponential initializes and returns a truncated exponential Retryer.

func Linear

func Linear(duration time.Duration, setters ...Option) Retryer

Linear initializes and returns a linear Retryer.

type Ticker

type Ticker interface {
	Tick() time.Duration
	StopChan() <-chan struct{}
	Stop()
}

Ticker defines the requirements for providing a clock to the retry logic.

type TimeoutError

type TimeoutError struct{}

TimeoutError represents a timeout error.

func (TimeoutError) Error

func (TimeoutError) Error() string

Jump to

Keyboard shortcuts

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