Struct: retry.ExponentialJitterBackoff

import "../ibm-cos-sdk-go-v2/aws/retry"

Overview

ExponentialJitterBackoff provides backoff delays with jitter based on the number of attempts.

Implemented Interfaces

types.AnalyticsFilter, retry.BackoffDelayer, v4.HTTPPresigner, s3.HTTPPresignerV4, types.MetricsFilter, s3.PresignPost, arn.S3ObjectLambdaARN, types.SelectObjectContentEventStream

Constructor Functions collapse

Method Summary collapse

Function Details

func NewExponentialJitterBackoff(maxBackoff time.Duration) *ExponentialJitterBackoff

NewExponentialJitterBackoff returns an ExponentialJitterBackoff configured for the max backoff.



22
23
24
25
26
27
28
29
// File 'aws/retry/jitter_backoff.go', line 22

func NewExponentialJitterBackoff(maxBackoff time.Duration) *ExponentialJitterBackoff { return &ExponentialJitterBackoff{ maxBackoff: maxBackoff, maxBackoffAttempts: math.Log2( float64(maxBackoff) / float64(time.Second)), randFloat64: rand.CryptoRandFloat64, } }

Method Details

func (j *ExponentialJitterBackoff) BackoffDelay(attempt int, err error) (time.Duration, error)

BackoffDelay returns the duration to wait before the next attempt should be made. Returns an error if unable get a duration.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// File 'aws/retry/jitter_backoff.go', line 33

func (j *ExponentialJitterBackoff) BackoffDelay(attempt int, err error) (time.Duration, error) { if attempt > int(j.maxBackoffAttempts) { return j.maxBackoff, nil } b, err := j.randFloat64() if err != nil { return 0, err } // [0.0, 1.0) * 2 ^ attempts ri := int64(1 << uint64(attempt)) delaySeconds := b * float64(ri) return timeconv.FloatSecondsDur(delaySeconds), nil }