Documentation ¶
Overview ¶
Package retry implements a configurable retry mechanism that can be embedded in any class needing a retry-on-error system.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsErrPermaFail ¶
IsErrPermaFail checks whether an `error` is a Retrier permanent fail
func IsErrWillRetry ¶
IsErrWillRetry checks whether an `error` is a Retrier temporary fail
Types ¶
type Config ¶
type Config struct { Name string AttemptMethod func() error Strategy Strategy RetryCount uint RetryDelay time.Duration InitialRetryDelay time.Duration MaxRetryDelay time.Duration // contains filtered or unexported fields }
Config contains all the required parameters for Retrier
type Error ¶
Error is a custom error type that is returned by the Retrier you can get its Status with IsRetryError()
func IsRetryError ¶
IsRetryError checks an `error` object to tell if it's a Retry.Error
type Retrier ¶
Retrier implements a configurable retry mechanism than can be embedded in any class providing attempt logic as a `func() error` method. See the unit test for an example.
func (*Retrier) LastError ¶ added in v0.9.0
LastError allows users to know what the last retry failure error was
func (*Retrier) RetryStatus ¶
RetryStatus allows users to query the status
func (*Retrier) SetupRetrier ¶
SetupRetrier must be called before calling other methods
func (*Retrier) TriggerRetry ¶
TriggerRetry triggers a new retry and returns the result
type Status ¶
type Status int
Status is returned by Retrier object to inform user classes
const ( // NeedSetup is the default value: SetupRetrier must be called NeedSetup Status = iota // Default zero value // Idle means the Retrier is ready for Try to be called Idle // OK means the object is available OK // FailWillRetry informs users the object is not available yet, // but they should retry later FailWillRetry // PermaFail informs the user the object will not be available. PermaFail )
type Strategy ¶
type Strategy int
Strategy sets how the Retrier should handle failure
const ( // OneTry is the default value: only try one, then permafail OneTry Strategy = iota // Default zero value // RetryCount sets the Retrier to try a fixed number of times RetryCount // Backoff retries often at the beginning and then, less often Backoff // JustTesting forces an OK status for unit tests that require a // non-functional object but no failure on init (eg. docker) JustTesting )