Documentation ¶
Index ¶
- Constants
- Variables
- func Do(op func() error, retryOptions ...RetryOption) error
- func IsMaxRetriesReached(err error) bool
- func IsTimeout(err error) bool
- func Not(checker func(err error) bool) func(err error) bool
- type RetryOption
- func AfterRetry(afterRetry func(err error)) RetryOption
- func AfterRetryLimit(afterRetryLimit func(err error)) RetryOption
- func MaxTries(tries int) RetryOption
- func RetryChecker(checker func(err error) bool) RetryOption
- func Sleep(d time.Duration) RetryOption
- func Timeout(d time.Duration) RetryOption
Constants ¶
const ( DefaultMaxTries = 3 DefaultTimeout = time.Duration(15 * time.Second) )
Variables ¶
var ( TimeoutError = errgo.New("Operation aborted. Timeout occured") MaxRetriesReachedError = errgo.New("Operation aborted. Too many errors.") )
Functions ¶
func Do ¶
func Do(op func() error, retryOptions ...RetryOption) error
Do performs the given operation. Based on the options, it can retry the operation, if it failed.
The following options are supported: * RetryChecker(func(err error) bool) - If this func returns true for the returned error, the operation is tried again * MaxTries(int) - Maximum number of calls to op() before aborting with MaxRetriesReached * Timeout(time.Duration) - Maximum number of time to try to perform this op before aborting with TimeoutReached * Sleep(time.Duration) - time to sleep after error failed op()
Defaults:
Timeout = 15 seconds MaxRetries = 5 Retryer = errgo.Any Sleep = No sleep
func IsMaxRetriesReached ¶
IsMaxRetriesReached returns true if the cause of the given error is a MaxRetriesReachedError.
Types ¶
type RetryOption ¶
type RetryOption func(options *retryOptions)
func AfterRetry ¶
func AfterRetry(afterRetry func(err error)) RetryOption
AfterRetry is called after a retry and can be used e.g. to emit events.
func AfterRetryLimit ¶
func AfterRetryLimit(afterRetryLimit func(err error)) RetryOption
AfterRetryLimit is called after a retry limit is reached and can be used e.g. to emit events.
func MaxTries ¶
func MaxTries(tries int) RetryOption
MaxTries specifies the maximum number of times op will be called by Do().
func RetryChecker ¶
func RetryChecker(checker func(err error) bool) RetryOption
RetryChecker defines whether the given error is an error that can be retried.
func Sleep ¶
func Sleep(d time.Duration) RetryOption
func Timeout ¶
func Timeout(d time.Duration) RetryOption
Timeout specifies the maximum time that should be used before aborting the retry loop. Note that this does not abort the operation in progress.