Class: God::Behaviors::NotifyWhenFlapping

Inherits:
God::Behavior show all
Defined in:
lib/god/behaviors/notify_when_flapping.rb

Instance Attribute Summary collapse

Attributes inherited from God::Behavior

#watch

Instance Method Summary collapse

Methods inherited from God::Behavior

#after_restart, #after_start, #after_stop, #before_stop, #friendly_name, generate

Methods included from Configurable

#base_name, complain, #complain, #friendly_name, #prepare, #reset

Constructor Details

#initializeNotifyWhenFlapping

Returns a new instance of NotifyWhenFlapping.



9
10
11
12
# File 'lib/god/behaviors/notify_when_flapping.rb', line 9

def initialize
  super
  @startup_times = []
end

Instance Attribute Details

#failuresObject

number of failures



5
6
7
# File 'lib/god/behaviors/notify_when_flapping.rb', line 5

def failures
  @failures
end

#notifierObject

class to notify with



7
8
9
# File 'lib/god/behaviors/notify_when_flapping.rb', line 7

def notifier
  @notifier
end

#secondsObject

number of seconds



6
7
8
# File 'lib/god/behaviors/notify_when_flapping.rb', line 6

def seconds
  @seconds
end

Instance Method Details

#before_restartObject



34
35
36
37
38
# 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_startObject



28
29
30
31
32
# 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?Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
21
22
23
24
25
26
# 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