4 class NotifyWhenFlapping < Behavior
5 attr_accessor :failures # number of failures
6 attr_accessor :seconds # number of seconds
7 attr_accessor :notifier # class to notify with
16 valid &= complain("You must specify the 'failures' attribute for :notify_when_flapping") unless self.failures
17 valid &= complain("You must specify the 'seconds' attribute for :notify_when_flapping") unless self.seconds
18 valid &= complain("You must specify the 'notifier' attribute for :notify_when_flapping") unless self.notifier
20 # Must take one arg or variable args
21 unless self.notifier.respond_to?(:notify) and [1,-1].include?(self.notifier.method(:notify).arity)
22 valid &= complain("The 'notifier' must have a method 'notify' which takes 1 or variable args")
31 check_for_flapping(now)
37 check_for_flapping(now)
42 def check_for_flapping(now)
43 @startup_times.select! {|time| time >= now - self.seconds }
44 if @startup_times.length >= self.failures
45 self.notifier.notify("#{self.watch.name} has called start/restart #{@startup_times.length} times in #{self.seconds} seconds")