Documentation ¶
Index ¶
Constants ¶
const Infinite = -1
Variables ¶
var ( ErrReachedMaxRetries = errors.New("retry: reached max retries") ErrUnretryableError = errors.New("retry: unretryable error") )
Functions ¶
This section is empty.
Types ¶
type Backoff ¶
func DefaultBackoff ¶
func DefaultBackoff() Backoff
type DoOption ¶
type DoOption func(c *doConfig)
func WithErrorHandler ¶ added in v0.0.63
func WithRetryableErrors ¶ added in v0.0.63
If UnretryableErrors and RetryableErrors are both applied, UnretryableErrors will be prioritized.
func WithUnretryableErrors ¶
If UnretryableErrors and RetryableErrors are both applied, UnretryableErrors will be prioritized.
type Jitter ¶
func DefaultJitter ¶
func DefaultJitter(opts ...JitterOption) Jitter
type JitterOption ¶
type JitterOption func(j *jitterConfig)
func WithDefaultJitterRand ¶ added in v0.0.62
func WithDefaultJitterRand(rnd *rand.Rand) JitterOption
func WithDefaultJitterRange ¶ added in v0.0.63
func WithDefaultJitterRange(minJitter, maxJitter time.Duration) JitterOption
type Option ¶
type Option func(c *Config)
func WithBackoff ¶
func WithJitter ¶
func WithMaxRetries ¶
type Retryer ¶
type Retryer struct {
// contains filtered or unexported fields
}
WARNING: Retryer should not be used across goroutines. Generate Retryer from Config for each goroutine.
func New ¶
New returns *retry.Retryer. *retry.Retryer provides methods to facilitate retry execution.
WARNING: Retryer should not be used across goroutines. Generate Retryer from Config for each goroutine.
Is used as follows:
ctx := context.Background() c := retry.NewConfig(10*time.Millisecond, 500*time.Millisecond, retry.WithMaxRetries(10)) r := retry.New(ctx, c) for r.Retry() { if r.Retries() == 0 { fmt.Printf("FIRSTTRY! time=%s retries=%d retryAfter=%s\n", time.Now(), r.Retries(), r.RetryAfter()) continue } fmt.Printf("RETRYING! time=%s retries=%d retryAfter=%s\n", time.Now(), r.Retries(), r.RetryAfter()) } fmt.Printf("COMPLETE! time=%s retries=%d error=%v\n", time.Now(), r.Retries(), r.Err())
Then, yields the following results:
FIRSTTRY! time=2009-11-10 23:00:00 +0000 UTC m=+0.000000001 retries=0 retryAfter=10ms RETRYING! time=2009-11-10 23:00:00.01 +0000 UTC m=+0.010000001 retries=1 retryAfter=20ms RETRYING! time=2009-11-10 23:00:00.03 +0000 UTC m=+0.030000001 retries=2 retryAfter=40ms RETRYING! time=2009-11-10 23:00:00.07 +0000 UTC m=+0.070000001 retries=3 retryAfter=80ms RETRYING! time=2009-11-10 23:00:00.15 +0000 UTC m=+0.150000001 retries=4 retryAfter=160ms RETRYING! time=2009-11-10 23:00:00.31 +0000 UTC m=+0.310000001 retries=5 retryAfter=320ms RETRYING! time=2009-11-10 23:00:00.63 +0000 UTC m=+0.630000001 retries=6 retryAfter=500ms RETRYING! time=2009-11-10 23:00:01.13 +0000 UTC m=+1.130000001 retries=7 retryAfter=500ms RETRYING! time=2009-11-10 23:00:01.63 +0000 UTC m=+1.630000001 retries=8 retryAfter=500ms RETRYING! time=2009-11-10 23:00:02.13 +0000 UTC m=+2.130000001 retries=9 retryAfter=500ms RETRYING! time=2009-11-10 23:00:02.63 +0000 UTC m=+2.630000001 retries=10 retryAfter=500ms COMPLETE! time=2009-11-10 23:00:02.63 +0000 UTC m=+2.630000001 retries=10 error=retry: reached max retries
If the maximum count of attempts is not given via retry.WithMaxRetries(), *retry.Retryer that retry.New() returned will retry infinitely many times.