Documentation ¶
Index ¶
- Variables
- func Action(run func() error, arbiter Arbiter, officer *Officer, first func() error, ...) error
- func WhileSuccessful(run func() error, delay time.Duration, timeout time.Duration) error
- func WhileSuccessfulDelay1Second(run func() error, timeout time.Duration) error
- func WhileSuccessfulDelay1SecondWithNotify(run func() error, timeout time.Duration, notify Notify) error
- func WhileSuccessfulDelay5Seconds(run func() error, timeout time.Duration) error
- func WhileSuccessfulDelay5SecondsWithNotify(run func() error, timeout time.Duration, notify Notify) error
- func WhileSuccessfulWithNotify(run func() error, delay time.Duration, timeout time.Duration, notify Notify) error
- func WhileUnsuccessful(run func() error, delay time.Duration, timeout time.Duration) error
- func WhileUnsuccessfulDelay1Second(run func() error, timeout time.Duration) error
- func WhileUnsuccessfulDelay1SecondWithNotify(run func() error, timeout time.Duration, notify Notify) error
- func WhileUnsuccessfulDelay5Seconds(run func() error, timeout time.Duration) error
- func WhileUnsuccessfulDelay5SecondsWithNotify(run func() error, timeout time.Duration, notify Notify) error
- func WhileUnsuccessfulWhereRetcode255Delay5SecondsWithNotify(run func() error, timeout time.Duration, notify Notify) error
- func WhileUnsuccessfulWhereRetcode255WithNotify(run func() error, delay time.Duration, timeout time.Duration, notify Notify) error
- func WhileUnsuccessfulWithNotify(run func() error, delay time.Duration, timeout time.Duration, notify Notify) error
- type Arbiter
- type ErrLimit
- type ErrTimeout
- type Notify
- type Officer
- type Try
Constants ¶
This section is empty.
Variables ¶
var DefaultArbiter = PrevailDone(Max(10), Timeout(30*time.Second))
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) 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 can't fail)
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 WhileSuccessfulDelay1Second ¶
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 ¶
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 ¶
WhileUnsuccessful retries every 'delay' while 'run' is unsuccessful with a 'timeout'
func WhileUnsuccessfulDelay1Second ¶
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 ¶
WhileUnsuccessfulDelay5Seconds retries while 'run' is unsuccessful (ie 'run' returns an error != nil), waiting 5 seconds after each try, expiring after 'timeout'
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 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, expiting 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, expiting 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.
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 {
// contains filtered or unexported fields
}
ErrLimit is returned when the maximum attempts has been reached.
type ErrTimeout ¶
type ErrTimeout struct {
// contains filtered or unexported fields
}
ErrTimeout is returned when the time limit has been reached.
func (ErrTimeout) Error ¶
func (e ErrTimeout) Error() string
type Officer ¶
type Officer struct {
Block func(Try)
}
Officer sleeps or selects any amount of time for each try
func Exponential ¶
Exponential sleeps for duration base * 2^tries
func Fibonacci ¶
Fibonacci sleeps for duration * fib(tries) TODO:See if we can use a context to prevent the full calculation for each try...
func Incremental ¶
Incremental sleeps for duration + the number of tries