Documentation ¶
Overview ¶
Package retry is a wrapper around github.com/cenkalti/backoff that provides do-with-retry helper functions.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DoWithRetry ¶
func DoWithRetry(ctx context.Context, p Policy, isRetryable IsRetryable, notify backoff.Notify, fn RetryableFunc) error
DoWithRetry executes fn with retry according to policy p and with respect to context ctx. IsRetryable defines which errors lead to retry attempt (can be nil for any error). Notify can be used to receive notification on every retry with error and backoff delay (can be nil if no notifications required).
Types ¶
type ConstantBackoffPolicy ¶
type ConstantBackoffPolicy struct {
// contains filtered or unexported fields
}
ConstantBackoffPolicy means repeat up to max times with constant interval delays.
func NewConstantBackoffPolicy ¶
func NewConstantBackoffPolicy(interval time.Duration, maxRetryAttempts int) ConstantBackoffPolicy
NewConstantBackoffPolicy returns a constant backoff policy with given interval and max retry attempt count.
func (ConstantBackoffPolicy) NewBackOff ¶
func (p ConstantBackoffPolicy) NewBackOff() backoff.BackOff
NewBackOff implements retry.Policy.
type ExponentialBackoffPolicy ¶
type ExponentialBackoffPolicy struct {
// contains filtered or unexported fields
}
ExponentialBackoffPolicy means repeat up to max times with exponentially growing delays (1.5 multiplier).
func NewExponentialBackoffPolicy ¶
func NewExponentialBackoffPolicy(initialInterval time.Duration, maxRetryAttempts int) ExponentialBackoffPolicy
NewExponentialBackoffPolicy returns an exponential backoff policy with given initial interval and max retry attempt count.
func (ExponentialBackoffPolicy) NewBackOff ¶
func (p ExponentialBackoffPolicy) NewBackOff() backoff.BackOff
NewBackOff implements retry.Policy.
type IsRetryable ¶
IsRetryable defines a func that can tell if error is retryable as opposed to persistent.
type Policy ¶
type Policy interface {
NewBackOff() backoff.BackOff
}
Policy defines backoff strategy.
type PolicyFunc ¶
type PolicyFunc func() backoff.BackOff
The PolicyFunc type is an adapter to allow the use of ordinary functions as retry.Policy.
func (PolicyFunc) NewBackOff ¶
func (f PolicyFunc) NewBackOff() backoff.BackOff
NewBackOff implements retry.Policy.
type RetryableFunc ¶
RetryableFunc is function that does some work and can be potentially retried.