Module: Clicksign::RetryBackoff
- Defined in:
- lib/clicksign/retry_backoff.rb
Constant Summary collapse
- BASE_SECONDS =
0.5- CAP_SECONDS =
30.0
Class Method Summary collapse
- .ceiling(attempt) ⇒ Object
-
.delay(attempt, rng: Random) ⇒ Object
Full jitter: uniform in [0, ceiling) to spread retries and avoid thundering herd.
Class Method Details
.ceiling(attempt) ⇒ Object
10 11 12 |
# File 'lib/clicksign/retry_backoff.rb', line 10 def ceiling(attempt) [BASE_SECONDS * (2**(attempt - 1)), CAP_SECONDS].min.to_f end |
.delay(attempt, rng: Random) ⇒ Object
Full jitter: uniform in [0, ceiling) to spread retries and avoid thundering herd.
15 16 17 18 19 20 |
# File 'lib/clicksign/retry_backoff.rb', line 15 def delay(attempt, rng: Random) max = ceiling(attempt) return 0.0 if max <= 0 rng.rand(max) end |