Class: Resqued::Backoff
- Inherits:
-
Object
- Object
- Resqued::Backoff
- Defined in:
- lib/resqued/backoff.rb
Instance Method Summary collapse
-
#died ⇒ Object
Public: Tell backoff that the thing unexpectedly died.
-
#how_long? ⇒ Boolean
Public: How much longer until ‘wait?` will be false?.
-
#initialize(options = {}) ⇒ Backoff
constructor
A new instance of Backoff.
-
#started ⇒ Object
Public: Tell backoff that the thing we might want to back off from just started.
-
#wait? ⇒ Boolean
Public: Check if we should wait before starting again.
Constructor Details
#initialize(options = {}) ⇒ Backoff
Returns a new instance of Backoff.
3 4 5 6 7 8 |
# File 'lib/resqued/backoff.rb', line 3 def initialize( = {}) @time = .fetch(:time) { Time } @min = .fetch(:min) { 1.0 } @max = .fetch(:max) { 16.0 } @backoff_duration = @min end |
Instance Method Details
#died ⇒ Object
Public: Tell backoff that the thing unexpectedly died.
18 19 20 21 |
# File 'lib/resqued/backoff.rb', line 18 def died @backoff_duration = @backoff_duration ? [@backoff_duration * 2.0, @max].min : @min @last_event = :died end |
#how_long? ⇒ Boolean
Public: How much longer until ‘wait?` will be false?
29 30 31 |
# File 'lib/resqued/backoff.rb', line 29 def how_long? wait? ? next_start_at - now : nil end |
#started ⇒ Object
Public: Tell backoff that the thing we might want to back off from just started.
11 12 13 14 15 |
# File 'lib/resqued/backoff.rb', line 11 def started @last_started_at = now @backoff_duration = @min if @last_event == :start @last_event = :start end |
#wait? ⇒ Boolean
Public: Check if we should wait before starting again.
24 25 26 |
# File 'lib/resqued/backoff.rb', line 24 def wait? @last_started_at && next_start_at > now end |