class Resqued::Backoff
Public Class Methods
new(options = {})
click to toggle source
# File lib/resqued/backoff.rb, line 3 def initialize(options = {}) @time = options.fetch(:time) { Time } @min = options.fetch(:min) { 1.0 } @max = options.fetch(:max) { 16.0 } @backoff_duration = @min end
Public Instance Methods
died()
click to toggle source
Public: Tell backoff that the thing unexpectedly died.
# 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?()
click to toggle source
Public: How much longer until ‘wait?` will be false?
# File lib/resqued/backoff.rb, line 29 def how_long? wait? ? next_start_at - now : nil end
started()
click to toggle source
Public: Tell backoff that the thing we might want to back off from just started.
# 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?()
click to toggle source
Public: Check if we should wait before starting again.
# File lib/resqued/backoff.rb, line 24 def wait? @last_started_at && next_start_at > now end
Private Instance Methods
next_start_at()
click to toggle source
Private: The next time when you’re allowed to start a process.
# File lib/resqued/backoff.rb, line 36 def next_start_at @last_started_at && @backoff_duration ? @last_started_at + @backoff_duration : now end
now()
click to toggle source
Private.
# File lib/resqued/backoff.rb, line 41 def now @time.now end