Documentation ¶
Index ¶
Constants ¶
View Source
const Infinite = -1
Variables ¶
View Source
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 WithUnretryableErrors ¶
type Jitter ¶
func DefaultJitter ¶
func DefaultJitter(minJitter, maxJitter time.Duration, opts ...JitterOption) Jitter
type JitterOption ¶
type JitterOption func(j *jitter)
func WithJitterRand ¶
func WithJitterRand(rnd *rand.Rand) JitterOption
type Option ¶
type Option func(c *Config)
func WithBackoff ¶
func WithJitter ¶
func WithMaxRetries ¶
type Retryer ¶
type Retryer struct {
// contains filtered or unexported fields
}
func New ¶
New returns *retry.Retryer. *retry.Retryer provides methods to facilitate retry execution.
Is used as follows ( https://go.dev/play/p/nIWIWq-ib6b ):
c := retry.NewConfig(10*time.Millisecond, 500*time.Millisecond, retry.WithMaxRetries(10)) r := retry.New(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.
func (*Retryer) RetryAfter ¶
Click to show internal directories.
Click to hide internal directories.