Class: Tenax::Retry::Backoff::Linear
- Defined in:
- lib/tenax/retry/backoff/linear.rb
Overview
Linear backoff: delay grows in proportion to attempt number.
delay = base * attempt (capped at cap if provided)
Useful when you want some growth between attempts but not the aggressive doubling of exponential backoff.
Instance Method Summary collapse
-
#delay_for(attempt) ⇒ Float
Delay seconds.
-
#initialize(base:, cap: nil) ⇒ Linear
constructor
A new instance of Linear.
Constructor Details
#initialize(base:, cap: nil) ⇒ Linear
Returns a new instance of Linear.
25 26 27 28 29 30 31 32 33 |
# File 'lib/tenax/retry/backoff/linear.rb', line 25 def initialize(base:, cap: nil) raise ArgumentError, "base must be non-negative, got #{base}" if base.negative? raise ArgumentError, "cap must be non-negative, got #{cap}" if cap&.negative? super() @base = base.to_f @cap = cap&.to_f freeze end |
Instance Method Details
#delay_for(attempt) ⇒ Float
Returns delay seconds.
37 38 39 40 |
# File 'lib/tenax/retry/backoff/linear.rb', line 37 def delay_for(attempt) delay = @base * attempt @cap ? [delay, @cap].min : delay end |