retry

package
v21.11.1 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2022 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CommonArbiter = PrevailDone(Min(5), Max(10))

CommonArbiter allows between 5 and 10 retries

View Source
var DefaultArbiter = PrevailDone(Max(10), Timeout(temporal.BigDelay()))

DefaultArbiter allows 10 retries, with a maximum duration of 30 seconds

Functions

func Action

func Action(
	run func() error,
	arbiter Arbiter,
	officer *Officer,
	first func() error,
	last func() error,
	notify Notify,
) fail.Error

Action tries to execute 'run' following verdicts from arbiter, with delay decided by 'officer'. If defined, 'first' is executed before trying (and may fail), and last is executed after the tries (whatever the state of the tries is, and cannot fail)

func DefaultMetadataNotifier

func DefaultMetadataNotifier(metaID string) func(t Try, v verdict.Enum)

DefaultMetadataNotifier provides a default Notifier focused on metadata issues

func DefaultNotifier

func DefaultNotifier() func(t Try, v verdict.Enum)

DefaultNotifier provides a default Notifier

func DefaultNotifierWithContext

func DefaultNotifierWithContext(ctx context.Context) (func(t Try, v verdict.Enum), error)

DefaultNotifierWithContext Provides a notified based on context 'ctx'

func DefaultTimeoutSelector

func DefaultTimeoutSelector() func(action) fail.Error

DefaultTimeoutSelector provides a default selector between hard and soft timeouts

func LimitError

func LimitError(err error, limit uint) fail.Error

LimitError creates an error of type ErrLimit.

func NewAction added in v21.11.1

func NewAction(officer *Officer, arbiter Arbiter, run func() error, notify Notify, timeout time.Duration) *action

NewAction is a constructor for action

func NotifyByLog

func NotifyByLog(try Try, ver verdict.Enum)

NotifyByLog logs the status of each try

func StopRetryError

func StopRetryError(err error, msg ...interface{}) fail.Error

StopRetryError creates an error of type ErrStopRetry

func TimeoutError

func TimeoutError(err error, limit time.Duration, actual time.Duration, options ...data.ImmutableKeyValue) fail.Error

TimeoutError creates an error of type ErrTimeout

func TimeoutSelector

func TimeoutSelector(hard bool) func(action) fail.Error

TimeoutSelector chooses between loops with hard timeout or loops with soft timeout

func WhileSuccessful

func WhileSuccessful(run func() error, delay time.Duration, timeout time.Duration) fail.Error

WhileSuccessful retries while 'run' is successful (ie 'run' returns an error == nil), waiting a duration of 'delay' after each try, expiring after a duration of 'timeout'.

func WhileSuccessfulWithNotify

func WhileSuccessfulWithNotify(run func() error, delay time.Duration, timeout time.Duration, notify Notify) fail.Error

WhileSuccessfulWithNotify retries while 'run' is successful (ie 'run' returns an error == nil), waiting a duration of 'delay' after each try, expiring after a duration of 'timeout'. 'notify' is called after each try for feedback.

func WhileUnsuccessful

func WhileUnsuccessful(run func() error, delay time.Duration, timeout time.Duration) fail.Error

WhileUnsuccessful retries every 'delay' while 'run' is unsuccessful with a 'timeout'

func WhileUnsuccessfulWithAggregator

func WhileUnsuccessfulWithAggregator(run func() error, delay time.Duration, timeout time.Duration, arb ArbiterAggregator, notify Notify) fail.Error

WhileUnsuccessfulWithAggregator allows using another ArbiterAggregator instead of the default PrevailDone

func WhileUnsuccessfulWithHardTimeout

func WhileUnsuccessfulWithHardTimeout(run func() error, delay time.Duration, timeout time.Duration) fail.Error

WhileUnsuccessfulWithHardTimeout retries every 'delay' while 'run' is unsuccessful with a 'timeout'

func WhileUnsuccessfulWithHardTimeoutWithNotifier

func WhileUnsuccessfulWithHardTimeoutWithNotifier(run func() error, delay time.Duration, timeout time.Duration, notify Notify) fail.Error

WhileUnsuccessfulWithHardTimeoutWithNotifier retries every 'delay' while 'run' is unsuccessful with a 'timeout'

func WhileUnsuccessfulWithLimitedRetries

func WhileUnsuccessfulWithLimitedRetries(run func() error, delay time.Duration, timeout time.Duration, retries uint) fail.Error

WhileUnsuccessfulWithLimitedRetries uses Unsuccessful and Max arbiters

func WhileUnsuccessfulWithNotify

func WhileUnsuccessfulWithNotify(run func() error, delay time.Duration, timeout time.Duration, notify Notify) fail.Error

WhileUnsuccessfulWithNotify retries while 'run' is unsuccessful (ie 'run' returns an error != nil), waiting 'delay' after each try, expiring after 'timeout'

Types

type Arbiter

type Arbiter func(Try) (verdict.Enum, fail.Error)

Arbiter sleeps or selects any amount of time for each attempt.

func Max

func Max(limit uint) Arbiter

Max errors after a limited number of tries, while the last try returned an error

func Min

func Min(limit uint) Arbiter

Min errors after a limited number of tries, while the last try returned an error

func OrArbiter

func OrArbiter(arbiters ...Arbiter) Arbiter

func PrevailDone

func PrevailDone(arbiters ...Arbiter) Arbiter

PrevailDone aggregates verdicts from Arbiters for a try: - Returns Abort and the error as soon as an Abort is decided. - If at least one arbiter return Done without any Abort, returns Done with nil error. - Otherwise returns Retry with nil error.

func PrevailRetry

func PrevailRetry(arbiters ...Arbiter) Arbiter

PrevailRetry aggregates verdicts from Arbiters for a try: - Returns Abort and the error as soon as an arbiter decides for an Abort. - If at least one arbiter returns Retry without any Abort from others, returns Retry with nil error. - Otherwise returns Done with nil error.

func Successful

func Successful() Arbiter

Successful returns Retry when the try produced no error; returns Done otherwise

func Timeout

func Timeout(limit time.Duration) Arbiter

Timeout returns Abort after a duration of time passes since the first try, while the try returns an error; returns Done if no error occurred during the last try

func Unsuccessful

func Unsuccessful() Arbiter

Unsuccessful returns Retry when the try produced an error; returns Done otherwise

type ArbiterAggregator

type ArbiterAggregator func(arbiters ...Arbiter) Arbiter

ArbiterAggregator this type helps easy replacement of PrevailDone

type Backoff

type Backoff func(duration time.Duration) *Officer

Backoff is the type that must implement algorithms that space out retries to avoid congestion

func BackoffSelector

func BackoffSelector() Backoff

BackoffSelector allows change the backoff delays between retries

type ErrLimit

type ErrLimit = fail.ErrOverflow

ErrLimit is used when a limit is reached.

type ErrStopRetry

type ErrStopRetry = fail.ErrAborted

ErrStopRetry is returned when the context needs to stop the retries

type ErrTimeout

type ErrTimeout = fail.ErrTimeout

ErrTimeout is used when a timeout occurs.

type Notify

type Notify func(Try, verdict.Enum)

Notify ...

type Officer

type Officer struct {
	Block func(Try)
	// contains filtered or unexported fields
}

Officer sleeps or selects any amount of time for each try

func Constant

func Constant(duration time.Duration) *Officer

Constant sleeps for duration duration

func Exponential

func Exponential(base time.Duration) *Officer

Exponential sleeps for duration base * 2^tries

func Fibonacci

func Fibonacci(base time.Duration) *Officer

Fibonacci sleeps for duration * fib(tries)

func Incremental

func Incremental(duration time.Duration) *Officer

Incremental sleeps for duration + the number of tries

func Linear

func Linear(duration time.Duration) *Officer

Linear sleeps for duration * the number of tries

func Randomized

func Randomized(bottom time.Duration, top time.Duration) *Officer

type Option added in v21.11.1

type Option func(thing *action) error // to set Officer and timeout

type Try

type Try struct {
	Start time.Time
	Count uint
	Err   error
}

Try keeps track of the number of tries, starting from 1. Action is valid only when Err is nil.

Directories

Path Synopsis
enums

Jump to

Keyboard shortcuts

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