class God::Behaviors::NotifyWhenFlapping

Attributes

failures[RW]
notifier[RW]
seconds[RW]

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/god/behaviors/notify_when_flapping.rb, line 9
def initialize
  super
  @startup_times = []
end

Public Instance Methods

before_restart() click to toggle source
# File lib/god/behaviors/notify_when_flapping.rb, line 34
def before_restart
  now = Time.now.to_i
  @startup_times << now
  check_for_flapping(now)
end
before_start() click to toggle source
# File lib/god/behaviors/notify_when_flapping.rb, line 28
def before_start
  now = Time.now.to_i
  @startup_times << now
  check_for_flapping(now)
end
valid?() click to toggle source
# File lib/god/behaviors/notify_when_flapping.rb, line 14
def valid?
  valid = true
  valid &= complain("Attribute 'failures' must be specified", self) unless self.failures
  valid &= complain("Attribute 'seconds' must be specified", self) unless self.seconds
  valid &= complain("Attribute 'notifier' must be specified", self) unless self.notifier

  # Must take one arg or variable args
  unless self.notifier.respond_to?(:notify) and [1,-1].include?(self.notifier.method(:notify).arity)
    valid &= complain("The 'notifier' must have a method 'notify' which takes 1 or variable args", self)
  end

  valid
end

Private Instance Methods

check_for_flapping(now) click to toggle source
# File lib/god/behaviors/notify_when_flapping.rb, line 42
def check_for_flapping(now)
  @startup_times.select! {|time| time >= now - self.seconds }
  if @startup_times.length >= self.failures
    self.notifier.notify("#{self.watch.name} has called start/restart #{@startup_times.length} times in #{self.seconds} seconds")
  end
end