class Racecar::Pause
Attributes
pauses_count[R]
Public Class Methods
new(timeout: nil, max_timeout: nil, exponential_backoff: false)
click to toggle source
# File lib/racecar/pause.rb, line 7 def initialize(timeout: nil, max_timeout: nil, exponential_backoff: false) @started_at = nil @pauses_count = 0 @timeout = timeout @max_timeout = max_timeout @exponential_backoff = exponential_backoff end
Public Instance Methods
backoff_interval()
click to toggle source
# File lib/racecar/pause.rb, line 48 def backoff_interval return Float::INFINITY if @timeout.nil? backoff_factor = @exponential_backoff ? 2**@pauses_count : 1 timeout = backoff_factor * @timeout timeout = @max_timeout if @max_timeout && timeout > @max_timeout timeout end
expired?()
click to toggle source
# File lib/racecar/pause.rb, line 38 def expired? return false if @timeout.nil? return true unless @ends_at Time.now >= @ends_at end
pause!()
click to toggle source
# File lib/racecar/pause.rb, line 15 def pause! @started_at = Time.now @ends_at = @started_at + backoff_interval unless @timeout.nil? @pauses_count += 1 end
pause_duration()
click to toggle source
# File lib/racecar/pause.rb, line 30 def pause_duration if paused? Time.now - @started_at else 0 end end
paused?()
click to toggle source
# File lib/racecar/pause.rb, line 26 def paused? !@started_at.nil? end
reset!()
click to toggle source
# File lib/racecar/pause.rb, line 44 def reset! @pauses_count = 0 end
resume!()
click to toggle source
# File lib/racecar/pause.rb, line 21 def resume! @started_at = nil @ends_at = nil end