retry

package
v3.36.1 Latest Latest
Warning

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

Go to latest
Published: May 26, 2022 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Constant added in v3.36.0

func Constant(interval time.Duration) (strategy, strategyType)

Constant returns a strategy that always returns the same value, the interval passed in as an arg to the function Semantically, when this is used with a retry.retrier, it means that the retrier will always wait the given duration before retrying

func Exponential added in v3.36.0

func Exponential(base, adjustment time.Duration) (strategy, strategyType)

Exponential returns a strategy that increases expontially based on the number of attempts the retrier has made It uses the calculation: adjustment + (base ** attempts) + jitter

func TryForever added in v3.36.0

func TryForever() retrierOpt

TryForever causes the retrier to to never give up retrying, until either the operation succeeds, or the operation calls retrier.Break()

func WithJitter added in v3.36.0

func WithJitter() retrierOpt

WithJitter enables jitter on the retrier, which will cause all of the retries to wait a random amount of time < 1 second The idea here is to avoid thundering herds - retries that are in parallel will happen at slightly different times when jitter is enabled, whereas if jitter is disabled, all the retries might happen at the same time, causing further load on the system that we're tryung to do something with

func WithMaxAttempts added in v3.36.0

func WithMaxAttempts(maxAttempts int) retrierOpt

WithMaxAttempts sets the maximum number of retries that a retrier will attempt

func WithRand added in v3.36.0

func WithRand(rand *rand.Rand) retrierOpt

func WithSleepFunc added in v3.36.0

func WithSleepFunc(f func(time.Duration)) retrierOpt

WithSleepFunc sets the function that the retrier uses to sleep between successive attempts Only really useful for testing

func WithStrategy added in v3.36.0

func WithStrategy(strategy strategy, strategyType strategyType) retrierOpt

WithStrategy sets the retry strategy that the retrier will use to determine how long to wait between retries

Types

type Retrier added in v3.36.0

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

func NewRetrier added in v3.36.0

func NewRetrier(opts ...retrierOpt) *Retrier

NewRetrier creates a new instance of the Retrier struct. Pass in retrierOpt functions to customise the behaviour of the retrier

func (*Retrier) AttemptCount added in v3.36.0

func (r *Retrier) AttemptCount() int

func (*Retrier) Break added in v3.36.0

func (r *Retrier) Break()

Break causes the Retrier to stop retrying after it completes the next retry cycle

func (*Retrier) Do added in v3.36.0

func (r *Retrier) Do(callback func(*Retrier) error) error

Do is the core loop of a Retrier. It defines the operation that the Retrier will attempt to perform, retrying it if necessary Calling retrier.Do(someFunc) will cause the Retrier to attempt to call the function, and if it returns an error, retry it using the settings provided to it.

func (*Retrier) MarkAttempt added in v3.36.0

func (r *Retrier) MarkAttempt()

MarkAttempt increments the attempt count for the retrier. This affects ShouldGiveUp, and also affects the retry interval for Exponential retry strategy

func (*Retrier) NextInterval added in v3.36.0

func (r *Retrier) NextInterval() time.Duration

NextInterval returns the next interval that the retrier will use. Behind the scenes, it calls the function generated by either retrier's strategy

func (*Retrier) ShouldGiveUp added in v3.36.0

func (r *Retrier) ShouldGiveUp() bool

ShouldGiveUp returns whether the retrier should stop trying do do the thing it's been asked to do It returns true if the retry count is greater than r.maxAttempts, or if r.Break() has been called It returns false if the retrier is supposed to try forever

func (*Retrier) String added in v3.36.0

func (r *Retrier) String() string

Jump to

Keyboard shortcuts

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