lib/god/conditions/flapping.rb in god-0.5.0 vs lib/god/conditions/flapping.rb in god-0.6.0

- old
+ new

@@ -1,10 +1,44 @@ module God module Conditions + # Condition Symbol :flapping + # Type: Trigger + # + # Trigger when a Task transitions to or from a state or states a given number + # of times within a given period. + # + # Paramaters + # Required + # +times+ is the number of times that the Task must transition before + # triggering. + # +within+ is the number of seconds within which the Task must transition + # the specified number of times before triggering. You may use + # the sugar methods #seconds, #minutes, #hours, #days to clarify + # your code (see examples). + # --one or both of-- + # +from_state+ is the state (as a Symbol) from which the transition must occur. + # +to_state is the state (as a Symbol) to which the transition must occur. + # + # Optional: + # +retry_in+ is the number of seconds after which to re-monitor the Task after + # it has been disabled by the condition. + # +retry_times+ is the number of times after which to permanently unmonitor + # the Task. + # +retry_within+ is the number of seconds within which + # + # Examples + # + # Trigger if class Flapping < TriggerCondition - attr_accessor :times, :within, :from_state, :to_state, :retry_in, :retry_times, :retry_within + attr_accessor :times, + :within, + :from_state, + :to_state, + :retry_in, + :retry_times, + :retry_within def initialize self.info = "process is flapping" end @@ -62,29 +96,26 @@ Thread.new do sleep 1 # log msg = "#{self.watch.name} giving up" - Syslog.debug(msg) - LOG.log(self.watch, :info, msg) + applog(self.watch, :info, msg) end else # try again later Thread.new do sleep 1 - + # log msg = "#{self.watch.name} auto-reenable monitoring in #{self.retry_in} seconds" - Syslog.debug(msg) - LOG.log(self.watch, :info, msg) - + applog(self.watch, :info, msg) + sleep self.retry_in - + # log msg = "#{self.watch.name} auto-reenabling monitoring" - Syslog.debug(msg) - LOG.log(self.watch, :info, msg) - + applog(self.watch, :info, msg) + if self.watch.state == :unmonitored self.watch.monitor end end end \ No newline at end of file