Sha256: c629e53253549cf325d6b9d51466f3e1db356ee54ab53111c1ae4631c316f5c2

Contents?: true

Size: 1.14 KB

Versions: 4

Compression:

Stored size: 1.14 KB

Contents

module Eye::Process::Trigger

  def add_triggers
    if self[:triggers]
      self[:triggers].each do |type, cfg|
        add_trigger(cfg)
      end      
    end
  end

  def remove_triggers
    self.triggers = []
  end

  def check_triggers
    return if unmonitored?

    self.triggers.each do |trigger|
      unless trigger.check(self.states_history)
        on_flapping(trigger) if trigger.class == Eye::Trigger::Flapping
      end
    end
  end

private

  def add_trigger(cfg = {})
    trigger = Eye::Trigger.create(cfg, logger.prefix)
    self.triggers << trigger
  end

  def on_flapping(trigger)
    notify :error, 'flapping!'
    schedule :unmonitor, Eye::Reason.new(:flapping)

    @retry_times ||= 0
    retry_in = trigger.retry_in

    return unless retry_in
    return if trigger.retry_times && @retry_times >= trigger.retry_times

    schedule_in(retry_in.to_f, :retry_action)
  end

  def retry_action
    debug "trigger retry timer"
    return unless unmonitored?
    return unless state_reason.to_s.include?('flapping') # TODO: remove hackety

    schedule :start, Eye::Reason.new(:'retry start after flapping')
    @retry_times += 1
  end

end

Version data entries

4 entries across 4 versions & 2 rubygems

Version Path
reel-eye-0.3.2 lib/eye/process/trigger.rb
eye-0.3.2 lib/eye/process/trigger.rb
reel-eye-0.3.1 lib/eye/process/trigger.rb
eye-0.3.1 lib/eye/process/trigger.rb