Documentation ¶
Index ¶
- func Loop(action Action, strategies ...Strategy) error
- func Retry(action Action, strategies ...Strategy) (uint, error)
- type Action
- type Retrier
- type Strategy
- func Backoff(strategy backoff.Strategy, maxBackoff time.Duration) Strategy
- func BackoffWithJitter(strategy backoff.Strategy, maxBackoff time.Duration, jitter float64) Strategy
- func Limit(maxAttempts uint) Strategy
- func NonRetriableErrors(nonRetriableErrors ...error) Strategy
- func RetriableErrors(retriableErrors ...error) Strategy
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Loop ¶ added in v0.43.0
Loop executes the provided action infinitely, until one of the provided strategies indicates it should not be retried.
Unlike Retry, when the action returns with no error, the internal attempt counter is reset, and the action is retried.
func Retry ¶
Retry executes the provided action, potentially multiple times based off of the provided strategies. Retry will block until the action is successful, or one of the provided strategies indicate no further retries should be performed.
The strategies are executed in the provided order, so any strategies that induce delays should be specified last.
Types ¶
type Retrier ¶
Retrier retries the provided action.
func NewRetrier ¶
NewRetrier returns a Retrier that will retry actions based off of the provided strategies. If no strategies are provided, the retrier acts as a tight-loop, retrying until no error is returned from the action.
type Strategy ¶
Strategy is a function that determines whether or not an action should be retried. Strategies are allowed to delay or cause other side effects.
func Backoff ¶
Backoff returns a strategy that will delay the next retry, provided the action resulted in an error. The returned strategy will cause the caller (the retrier) to sleep.
func BackoffWithJitter ¶
func BackoffWithJitter(strategy backoff.Strategy, maxBackoff time.Duration, jitter float64) Strategy
BackoffWithJitter returns a strategy similar to Backoff, but induces a jitter on the total delay. The maxBackoff is calculated before the jitter.
The jitter parameter is a percentage of the total delay (after capping) that the timing can be off of. For example, a capped delay of 100ms with a jitter of 0.1 will result in a delay of 100ms +/- 10ms.
func Limit ¶
Limit returns a strategy that limits the total number of retries. maxAttempts should be >= 1, since the action is evaluateed first.
func NonRetriableErrors ¶
NonRetriableErrors returns a strategy that specifies which errors should not be retried.
func RetriableErrors ¶
RetriableErrors returns a strategy that specifies which errors can be retried.