Class: StagedEvent::BackoffTimer
- Inherits:
-
Object
- Object
- StagedEvent::BackoffTimer
- Defined in:
- lib/staged_event/backoff_timer.rb
Constant Summary collapse
- INCREMENTS_BEFORE_BACKOFF =
5
- MAX_VALUE =
25
Instance Method Summary collapse
- #increment ⇒ Object
-
#initialize ⇒ BackoffTimer
constructor
A new instance of BackoffTimer.
- #reset ⇒ Object
- #value ⇒ Object
Constructor Details
#initialize ⇒ BackoffTimer
Returns a new instance of BackoffTimer.
8 9 10 |
# File 'lib/staged_event/backoff_timer.rb', line 8 def initialize reset end |
Instance Method Details
#increment ⇒ Object
12 13 14 |
# File 'lib/staged_event/backoff_timer.rb', line 12 def increment @increments += 1 end |
#reset ⇒ Object
16 17 18 |
# File 'lib/staged_event/backoff_timer.rb', line 16 def reset @increments = 0 end |
#value ⇒ Object
20 21 22 23 24 25 |
# File 'lib/staged_event/backoff_timer.rb', line 20 def value # returns 1 until the timer has been incremented n times, after which it # returns n^2 (until reaching a set maximum) backoff_time = [ 1, increments - INCREMENTS_BEFORE_BACKOFF + 1 ].max**2 [ backoff_time, MAX_VALUE ].min end |