Documentation ¶
Overview ¶
Package retry implements a generic retry provider.
Basic Example ¶
You can use the retry provider to wrap a potentially flaky call:
res, err := http.Get("https://google.com") ... res, err := retry.Retry(ctx, func(_ context.Context, args interface{}) (interface{}, error) { return http.Get(args.(string)) }, "https://google.com") // note: the return type here is `(interface{}, error)`
You can also add additional parameters to the retry:
res, err := retry.Retry(ctx, func(_ context.Context, args interface{}) (interface{}, error) { return http.Get(args.(string)) }, "https://google.com", retry.OptMaxAttempts(10), retry.OptExponentialBackoff(time.Second))
Index ¶
Constants ¶
const ( DefaultMaxAttempts = 5 DefaultRetryDelay = time.Second )
Defaults
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ActionerFunc ¶ added in v1.20210615.7
type ActionerFunc = async.ActionerFunc
ActionerFunc is an alias to async.ActionerFunc.
type DelayProvider ¶
DelayProvider is a provider for retry delays.
func ConstantDelay ¶
func ConstantDelay(d time.Duration) DelayProvider
ConstantDelay returns a constant delay provider.
func ExponentialBackoff ¶
func ExponentialBackoff(d time.Duration) DelayProvider
ExponentialBackoff is a backoff provider that doubles the base delay each attempt.
type Option ¶
type Option func(*Retrier)
Option mutates retry options.
func OptConstantDelay ¶
OptConstantDelay sets the retry delay provider.
func OptDelayProvider ¶
func OptDelayProvider(delayProvider DelayProvider) Option
OptDelayProvider sets the retry delay provider.
func OptExponentialBackoff ¶
OptExponentialBackoff sets the retry delay provider.
func OptMaxAttempts ¶
OptMaxAttempts sets the max attempts.
func OptShouldRetryProvider ¶
func OptShouldRetryProvider(provider ShouldRetryProvider) Option
OptShouldRetryProvider sets the should retry provider.
type Retrier ¶ added in v1.20210615.7
type Retrier struct { MaxAttempts uint DelayProvider DelayProvider ShouldRetryProvider ShouldRetryProvider }
Retrier is the retry agent.
type ShouldRetryProvider ¶
ShouldRetryProvider is a function that returns if we should retry on an error or abort retries. Return `true` to continue to retry, and `false` otherwise to abort retries. If you do not specify a provider, all errors will be retried (`true` by default)