retry-go: github.com/giantswarm/retry-go Index | Files

package retry

import "github.com/giantswarm/retry-go"

Index

Package Files

error.go options.go retry.go

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.")
)

func Do Uses

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 Uses

func IsMaxRetriesReached(err error) bool

IsMaxRetriesReached returns true if the cause of the given error is a MaxRetriesReachedError.

func IsTimeout Uses

func IsTimeout(err error) bool

IsTimeout returns true if the cause of the given error is a TimeoutError.

func Not Uses

func Not(checker func(err error) bool) func(err error) bool

Not is a helper to invert another .

type RetryOption Uses

type RetryOption func(options *retryOptions)

func AfterRetry Uses

func AfterRetry(afterRetry func(err error)) RetryOption

AfterRetry is called after a retry and can be used e.g. to emit events.

func AfterRetryLimit Uses

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 Uses

func MaxTries(tries int) RetryOption

MaxTries specifies the maximum number of times op will be called by Do().

func RetryChecker Uses

func RetryChecker(checker func(err error) bool) RetryOption

RetryChecker defines whether the given error is an error that can be retried.

func Sleep Uses

func Sleep(d time.Duration) RetryOption

func Timeout Uses

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.

Package retry imports 2 packages (graph) and is imported by 3 packages. Updated 2016-07-22. Refresh now. Tools for package owners.