retry

package module
v0.0.0-...-7cefc1c Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2019 License: MIT Imports: 2 Imported by: 0

README

retry

(Another) retriable errors package for go

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(r *Retriable)

Option is a functional option for a Retriable

func WithDuration

func WithDuration(d time.Duration) Option

WithDuration sets the waiter to use a Duration WaiterFunc with the specified duration

func WithExponentialBackoff

func WithExponentialBackoff(d time.Duration) Option

WithExponentialBackoff sets the waiter to use an ExponentialBackoff WaiterFunc with the specified duration

func WithIncrementalBackoff

func WithIncrementalBackoff(d time.Duration) Option

WithIncrementalBackoff sets the waiter to use an IncrementalBackoff WaiterFunc with the specified duration

func WithMaxAttempts

func WithMaxAttempts(maxAttempts uint) Option

WithMaxAttempts sets the maximum number of attempts for a Retriable

func WithMaxWait

func WithMaxWait(maxDuration time.Duration) Option

WithMaxWait sets the maximum amount of duration to wait between retries, regardless of what is returned from the Waiter

func WithWaiter

func WithWaiter(waiter Waiter) Option

WithWaiter sets the waiter used to determine the amount of time to wait between retries for a Retriable

type PermanentError

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

PermanentError signals that the operation should not be retried

func Permanent

func Permanent(err error) PermanentError

Permanent wraps the given err in a PermanentError

type Retriable

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

Retriable represents an action that is retriable given an error

func Default

func Default() *Retriable

Default creates a new Retriable that retries 3 times, sleeping for a second between each retry

func New

func New(opts ...Option) *Retriable

New creates a new Retriable with optional functional options Note: the default Retriable retries 3 times, sleeping for a second between each retry

func (*Retriable) Do

func (r *Retriable) Do(f func() error) error

Do calls the function f provided, retrying on any errors according to the properties defined on the Retriable r

type Waiter

type Waiter interface {
	Wait(attempt uint, err error) time.Duration
}

Waiter is an interface that determines the amount of time to wait in between retries given the number of attempts and error that occurred

type WaiterFunc

type WaiterFunc func(attempt uint, err error) time.Duration

WaiterFunc is a function that can act as a Waiter

func Duration

func Duration(d time.Duration) WaiterFunc

Duration is a WaiterFunc that waits for a static duration

func ExponentialBackoff

func ExponentialBackoff(d time.Duration) WaiterFunc

ExponentialBackoff is a WaiterFunc that waits for a duration d multiplied by the number of attempts^2 that have occurred for the Retriable ex: 1, 4, 9, 16, 25 * time.Seconds

func IncrementalBackoff

func IncrementalBackoff(d time.Duration) WaiterFunc

IncrementalBackoff is a WaiterFunc that waits for a duration d multiplied by the number of attempts that have occurred for the Retriable ex: 1, 2, 3, 4, 5 * time.Seconds

func (WaiterFunc) Wait

func (w WaiterFunc) Wait(attempt uint, err error) time.Duration

Wait returns the amount of time to wait given the attempt

Jump to

Keyboard shortcuts

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