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("Attribute 'failures' must be specified", self) unless self.failures
17 valid &= complain("Attribute 'seconds' must be specified", self) unless self.seconds
18 valid &= complain("Attribute 'notifier' must be specified", self) 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", self)
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")