MCPcopy Index your code
hub / github.com/riverqueue/river / retrySeconds

Method retrySeconds

retry_policy.go:75–94  ·  view source on GitHub ↗

nolint:gochecknoglobals Gets a number of retry seconds for the given attempt, random jitter included.

(attempt int)

Source from the content-addressed store, hash-verified

73
74// Gets a number of retry seconds for the given attempt, random jitter included.
75func (p *DefaultClientRetryPolicy) retrySeconds(attempt int) float64 {
76 retrySeconds := p.retrySecondsWithoutJitter(attempt)
77
78 // After hitting maximum retry durations jitter is no longer applied because
79 // it might overflow time.Duration. That's okay though because so much
80 // jitter will already have been applied up to this point (jitter measured
81 // in decades) that jobs will no longer run anywhere near contemporaneously
82 // unless there's been considerable manual intervention.
83 if retrySeconds == maxDurationSeconds {
84 return maxDurationSeconds
85 }
86
87 // Jitter number of seconds +/- 10%.
88 retrySeconds += retrySeconds * (rand.Float64()*0.2 - 0.1)
89
90 // Cap retrySeconds once more in case adding random jitter pushed it over
91 // maxDurationSeconds. (This should never realistically happen, but protect
92 // against it just in case.)
93 return min(retrySeconds, maxDurationSeconds)
94}
95
96// Gets a base number of retry seconds for the given attempt, jitter excluded.
97// If the number of seconds returned would overflow time.Duration if it were to

Callers 3

NextRetryMethod · 0.95

Calls 1

Tested by 2