Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type FailFastError ¶
type FailFastError struct {
// contains filtered or unexported fields
}
func FailFast ¶
func FailFast(err error) *FailFastError
FailFast allows code to break out of the retry if they encounter a situation they would prefer to fail fast. - `retry.Do` will not retry if the error is of type `FailFastError`, instead it will immediately return the wrapped error.
func (*FailFastError) Error ¶
func (f *FailFastError) Error() string
func (*FailFastError) Unwrap ¶
func (f *FailFastError) Unwrap() error
Unwrap function means FailFastError will still work with errors.Is and errors.As for the wrapped error
type Strategy ¶
type Strategy interface { // NextRetryInterval calls can be considered as marking the completion of an attempt NextRetryInterval() time.Duration // returns the duration to sleep before making the next attempt (may not be fixed, e.g. if strategy is to back-off) Done() bool // returns true when caller should stop retrying Summary() string // message to summarise usage (i.e. number of retries, time take, if it failed and why, e.g. "timed out after 120 seconds (8 attempts)" Reset() // reset is called before the first attempt is made, can be used for recording start time or setting attempts to zero }
Strategy interface allows for flexible strategies for retrying/polling functions.
func NewBackoffAndRetryForeverStrategy ¶
func NewBackoffAndRetryForeverStrategy(backoffIntervals []time.Duration, retryInterval time.Duration) Strategy
NewBackoffAndRetryForeverStrategy will keep retrying until there is a success. For the first retries it will wait the durations specified by the `backoffIntervals` slice, after which it will use the `retryInterval` indefinitely Note: caller can still use retry.FailFast(err) to wrap an error if it wants to break out of the retry
func NewDoublingBackoffStrategy ¶
NewDoublingBackoffStrategy keeps retrying until successful or until it reaches maxRetries, doubling the initialInterval wait period after each additional retry to avoid exacerbating problems with failing traffic