MCPcopy
hub / github.com/docker/docker-agent / delay

Method delay

pkg/tools/lifecycle/supervisor.go:81–101  ·  view source on GitHub ↗

delay returns the wait time before attempt n (0-based).

(attempt int, randFloat func() float64)

Source from the content-addressed store, hash-verified

79
80// delay returns the wait time before attempt n (0-based).
81func (b Backoff) delay(attempt int, randFloat func() float64) time.Duration {
82 initial := b.Initial
83 if initial <= 0 {
84 initial = time.Second
85 }
86 mul := b.Multiplier
87 if mul <= 0 {
88 mul = 2
89 }
90 maxDelay := b.Max
91 if maxDelay <= 0 {
92 maxDelay = 32 * time.Second
93 }
94 d := min(time.Duration(float64(initial)*math.Pow(mul, float64(attempt))), maxDelay)
95 if b.Jitter > 0 {
96 j := min(b.Jitter, 1.0)
97 offset := (randFloat()*2 - 1) * j * float64(d)
98 d = max(time.Duration(float64(d)+offset), 0)
99 }
100 return d
101}
102
103// Policy controls how a Supervisor manages a connection over time. The
104// zero value gives the historical mcp.Toolset behaviour: RestartOnFailure,

Callers 2

ExportedBackoffDelayFunction · 0.80
tryRestartMethod · 0.80

Calls 1

DurationMethod · 0.80

Tested by 1

ExportedBackoffDelayFunction · 0.64