Documentation ¶
Index ¶
- Variables
- func Action(run func() error, arbiter Arbiter, officer *Officer, first func() error, ...) fail.Error
- func DefaultMetadataNotifier(metaID string) func(t Try, v verdict.Enum)
- func DefaultNotifier() func(t Try, v verdict.Enum)
- func DefaultNotifierWithContext(ctx context.Context) (func(t Try, v verdict.Enum), error)
- func DefaultTimeoutSelector() func(action) fail.Error
- func LimitError(err error, limit uint) fail.Error
- func NewAction(officer *Officer, arbiter Arbiter, run func() error, notify Notify, ...) *action
- func NotifyByLog(try Try, ver verdict.Enum)
- func StopRetryError(err error, msg ...interface{}) fail.Error
- func TimeoutError(err error, limit time.Duration, actual time.Duration, ...) fail.Error
- func TimeoutSelector(hard bool) func(action) fail.Error
- func WhileSuccessful(run func() error, delay time.Duration, timeout time.Duration) fail.Error
- func WhileSuccessfulWithNotify(run func() error, delay time.Duration, timeout time.Duration, notify Notify) fail.Error
- func WhileUnsuccessful(run func() error, delay time.Duration, timeout time.Duration) fail.Error
- func WhileUnsuccessfulWithAggregator(run func() error, delay time.Duration, timeout time.Duration, ...) fail.Error
- func WhileUnsuccessfulWithHardTimeout(run func() error, delay time.Duration, timeout time.Duration) fail.Error
- func WhileUnsuccessfulWithHardTimeoutWithNotifier(run func() error, delay time.Duration, timeout time.Duration, notify Notify) fail.Error
- func WhileUnsuccessfulWithLimitedRetries(run func() error, delay time.Duration, timeout time.Duration, retries uint) fail.Error
- func WhileUnsuccessfulWithNotify(run func() error, delay time.Duration, timeout time.Duration, notify Notify) fail.Error
- type Arbiter
- type ArbiterAggregator
- type Backoff
- type ErrLimit
- type ErrStopRetry
- type ErrTimeout
- type Notify
- type Officer
- type Option
- type Try
Constants ¶
This section is empty.
Variables ¶
var CommonArbiter = PrevailDone(Min(5), Max(10))
CommonArbiter allows between 5 and 10 retries
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 ¶
DefaultMetadataNotifier provides a default Notifier focused on metadata issues
func DefaultNotifier ¶
DefaultNotifier provides a default Notifier
func DefaultNotifierWithContext ¶
DefaultNotifierWithContext Provides a notified based on context 'ctx'
func DefaultTimeoutSelector ¶
DefaultTimeoutSelector provides a default selector between hard and soft timeouts
func LimitError ¶
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 ¶
NotifyByLog logs the status of each try
func StopRetryError ¶
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 ¶
TimeoutSelector chooses between loops with hard timeout or loops with soft timeout
func WhileSuccessful ¶
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 ¶
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 ¶
Arbiter sleeps or selects any amount of time for each attempt.
func PrevailDone ¶
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 ¶
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 ¶
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 ¶
ArbiterAggregator this type helps easy replacement of PrevailDone
type Backoff ¶
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 ErrStopRetry ¶
type ErrStopRetry = fail.ErrAborted
ErrStopRetry is returned when the context needs to stop the retries
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 Exponential ¶
Exponential sleeps for duration base * 2^tries
func Incremental ¶
Incremental sleeps for duration + the number of tries