retry

package
v19.10.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2019 License: Apache-2.0 Imports: 8 Imported by: 20

Documentation

Index

Constants

This section is empty.

Variables

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

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

View Source
var (
	// NotifyByLog logs the status of each try
	NotifyByLog = func(try Try, verdict Verdict.Enum) {
		logrus.Debugf("try #%d: verdict=%s, err=%v", try.Count, verdict.String(), try.Err)
	}
)

Functions

func Action

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

Action tries to executes '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 TimeoutError

func TimeoutError(limit time.Duration, err error) scerr.ErrTimeout

TimeoutError ...

func WhileSuccessful

func WhileSuccessful(run func() error, delay time.Duration, timeout time.Duration) 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 WhileSuccessfulDelay1Second

func WhileSuccessfulDelay1Second(run func() error, timeout time.Duration) error

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

func WhileSuccessfulDelay1SecondWithNotify

func WhileSuccessfulDelay1SecondWithNotify(run func() error, timeout time.Duration, notify Notify) error

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

func WhileSuccessfulDelay5Seconds

func WhileSuccessfulDelay5Seconds(run func() error, timeout time.Duration) error

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

func WhileSuccessfulDelay5SecondsWithNotify

func WhileSuccessfulDelay5SecondsWithNotify(run func() error, timeout time.Duration, notify Notify) error

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

func WhileSuccessfulWithNotify

func WhileSuccessfulWithNotify(run func() error, delay time.Duration, timeout time.Duration, notify Notify) 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) error

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

func WhileUnsuccessfulDelay1Second

func WhileUnsuccessfulDelay1Second(run func() error, timeout time.Duration) error

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

func WhileUnsuccessfulDelay1SecondWithNotify

func WhileUnsuccessfulDelay1SecondWithNotify(run func() error, timeout time.Duration, notify Notify) error

WhileUnsuccessfulDelay1SecondWithNotify retries while 'run' is unsuccessful (ie 'run' returns an error != nil), waiting 1 second after each try, expiring after a duration of 'timeout'. 'notify' is called after each try for feedback.

func WhileUnsuccessfulDelay5Seconds

func WhileUnsuccessfulDelay5Seconds(run func() error, timeout time.Duration) error

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

func WhileUnsuccessfulDelay5SecondsTimeout

func WhileUnsuccessfulDelay5SecondsTimeout(run func() error, timeout time.Duration) error

WhileUnsuccessfulDelay5SecondsTimeout ...

func WhileUnsuccessfulDelay5SecondsWithNotify

func WhileUnsuccessfulDelay5SecondsWithNotify(run func() error, timeout time.Duration, notify Notify) error

WhileUnsuccessfulDelay5SecondsWithNotify retries while 'run' is unsuccessful (ie 'run' returns an error != nil), waiting 5 seconds after each try, expiring after a duration of 'timeout'. 'notify' is called after each try for feedback.

func WhileUnsuccessfulTimeout

func WhileUnsuccessfulTimeout(run func() error, delay time.Duration, timeout time.Duration) error

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

func WhileUnsuccessfulWhereRetcode255Delay5SecondsWithNotify

func WhileUnsuccessfulWhereRetcode255Delay5SecondsWithNotify(run func() error, timeout time.Duration, notify Notify) error

WhileUnsuccessfulWhereRetcode255Delay5SecondsWithNotify retries while 'run' is unsuccessful (ie 'run' returns an error != nil and this error has 255 as exit status code), waiting 5 seconds after each try, expiring after a duration of 'timeout'. 'notify' is called after each try for feedback.

func WhileUnsuccessfulWhereRetcode255WithNotify

func WhileUnsuccessfulWhereRetcode255WithNotify(run func() error, delay time.Duration, timeout time.Duration, notify Notify) error

WhileUnsuccessfulWhereRetcode255WithNotify retries while 'run' is unsuccessful (ie 'run' returns an error != nil and this error has 255 as exit status code), waiting 'delay' after each try, expiring after 'timeout'

func WhileUnsuccessfulWithNotify

func WhileUnsuccessfulWithNotify(run func() error, delay time.Duration, timeout time.Duration, notify Notify) 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, 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

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.

func Timeout

func Timeout(limit time.Duration) Arbiter

Timeout returns Abort after a duration of time passes since the first try.

func Unsuccessful

func Unsuccessful() Arbiter

Unsuccessful returns Retry when the try produced an error.

func UnsuccessfulWhereRetcode255

func UnsuccessfulWhereRetcode255() Arbiter

UnsuccessfulWhereRetcode255 returns Retry when the try produced an error with code 255, all other codes are considered as successful and returns Done.

type ErrLimit

type ErrLimit struct {
	scerr.ErrCore
	// contains filtered or unexported fields
}

ErrLimit is returned when the maximum attempts has been reached.

func LimitError

func LimitError(limit uint, err error) ErrLimit

LimitError ...

func (ErrLimit) AddConsequence

func (e ErrLimit) AddConsequence(err error) error

AddConsequence adds an error 'err' to the list of consequences

func (ErrLimit) Cause

func (e ErrLimit) Cause() error

Cause returns the error cause

func (ErrLimit) Consequences

func (e ErrLimit) Consequences() []error

Consequences returns the list of consequences

func (ErrLimit) Error

func (e ErrLimit) Error() string

Error

type ErrStopRetry

type ErrStopRetry struct {
	scerr.ErrCore
}

ErrStopRetry is returned when the maximum attempts has been reached.

func StopRetryError

func StopRetryError(message string, err error) ErrStopRetry

StopRetryError ...

func (ErrStopRetry) AddConsequence

func (e ErrStopRetry) AddConsequence(err error) error

AddConsequence adds a consequence err to the list of consequences

func (ErrStopRetry) Cause

func (e ErrStopRetry) Cause() error

Cause returns the error cause

func (ErrStopRetry) Consequences

func (e ErrStopRetry) Consequences() []error

Consequences returns the list of consequences

func (ErrStopRetry) Error

func (e ErrStopRetry) Error() string

Error

type ErrTimeout

type ErrTimeout = scerr.ErrTimeout

ErrTimeout is an alias for utils.ErrTimeout

type Notify

type Notify func(Try, Verdict.Enum)

Notify ...

type Officer

type Officer struct {
	Block func(Try)
}

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(duration time.Duration) *Officer

Fibonacci sleeps for duration * fib(tries) TODO:See if we can use a context to prevent the full calculation for each try...

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

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