Documentation ¶
Overview ¶
Package retry provides a configurable construct to retry execution of flaky function calls. Retryer can repeatedly invoke function call, till it succeeds.
Index ¶
- Constants
- func AfterEachFail(failFn func(error)) func(*Retryer)
- func Do(fn func() error, opts ...func(*Retryer)) error
- func Ensure(ensureFn func(error)) func(*Retryer)
- func Not(errors []error) func(*Retryer)
- func On(errors []error) func(r *Retryer)
- func Recover() func(*Retryer)
- func Sleep(dur int) func(*Retryer)
- func SleepFn(sleepFn func(int)) func(*Retryer)
- func Tries(tries int) func(r *Retryer)
- type Retryer
Constants ¶
const MaxRetries = 10
MaxRetries is the maximum number of retries.
Variables ¶
This section is empty.
Functions ¶
func AfterEachFail ¶
AfterEachFail configures the Retryer to call failFn function after each of the failed attempts.
func Do ¶
Do is wrapper around Retryer, which doesn't expose the Retryer itself, only calls the function until it succeeds.
func Ensure ¶
Ensure sets a deferred function to be called, regardless of Retryer succeeding in running the function with or without an error.
func Not ¶
Not configures the Retryer to ignore all of the passed in errors and in case of them appearing doesn't retry function anymore.
func Recover ¶
func Recover() func(*Retryer)
Recover configures the Retryer to recover panics, returning an error containing the panic and it's stacktrace.
func Sleep ¶
Sleep configures the Retryer to sleep and delay the next execution of a function for certain duration [ms] after each failed attempt.
Types ¶
type Retryer ¶
type Retryer struct { Tries int On []error // On is the slice of errors, on which Retryer will retry a function Not []error // Not is the slice of errors which Retryer won't consider as needed to retry SleepDur time.Duration // Sleep duration in ms Recover bool // If enabled, panics will be recovered. SleepFn func(int) // Custom sleep function with access to the current # of attempts EnsureFn func(error) // DeferredFn is called after repeated function finishes, regardless of outcome AfterEachFailFn func(error) // Callback called after each of the failures (for example some logging) // contains filtered or unexported fields }
Retryer is configurable runner, which repeats function calls until it succeeds.