Class: Flapjack::Gateways::Oobetet::TimeChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/flapjack/gateways/oobetet.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ TimeChecker

Returns a new instance of TimeChecker.



141
142
143
144
145
146
147
148
149
150
151
152
153
154
# 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

Instance Method Details

#breach?(time) ⇒ Boolean

Returns:

  • (Boolean)


188
189
190
191
192
193
194
195
196
197
# 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) ⇒ Object



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# 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

#startObject



156
157
158
159
160
161
162
163
164
165
# 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_typeObject



167
168
169
# File 'lib/flapjack/gateways/oobetet.rb', line 167

def stop_type
  :signal
end