class Flapjack::Gateways::Oobetet::TimeChecker

Public Class Methods

new(opts = {}) click to toggle source
# File lib/flapjack/gateways/oobetet.rb, line 141
def initialize(opts = {})
  @lock   = opts[:lock]
  @stop_cond = opts[:stop_condition]
  @config = opts[:config]

  @max_latency = @config['max_latency'] || 300

  @times = { :last_problem  => nil,
             :last_recovery => nil,
             :last_ack      => nil,
             :last_ack_sent => nil }

  Flapjack.logger.debug("new oobetet pikelet with the following options: #{@config.inspect}")
end

Public Instance Methods

breach?(time) click to toggle source
# File lib/flapjack/gateways/oobetet.rb, line 188
def breach?(time)
  @lock.synchronize do
    Flapjack.logger.debug("check_timers: inspecting @times #{@times.inspect}")
    if @times[:last_problem] < (time - @max_latency)
      "haven't seen a test problem notification in the last #{@max_latency} seconds"
    elsif @times[:last_recovery] < (time - @max_latency)
      "haven't seen a test recovery notification in the last #{@max_latency} seconds"
    end
  end
end
receive_status(status, time) click to toggle source
# File lib/flapjack/gateways/oobetet.rb, line 171
def receive_status(status, time)
  @lock.synchronize do
    case status
    when 'problem'
      Flapjack.logger.debug("updating @times last_problem")
      @times[:last_problem] = time
    when 'recovery'
      Flapjack.logger.debug("updating @times last_recovery")
      @times[:last_recovery] = time
    when 'acknowledgement'
      Flapjack.logger.debug("updating @times last_ack")
      @times[:last_ack] = time
    end
    Flapjack.logger.debug("@times: #{@times.inspect}")
  end
end
start() click to toggle source
# File lib/flapjack/gateways/oobetet.rb, line 156
def start
  @lock.synchronize do
    t = Time.now.to_i
    @times[:last_problem]  = t
    @times[:last_recovery] = t
    @times[:last_ack]      = t
    @times[:last_ack_sent] = t
    @stop_cond.wait_until { @should_quit }
  end
end
stop_type() click to toggle source
# File lib/flapjack/gateways/oobetet.rb, line 167
def stop_type
  :signal
end