Class: God::Behaviors::NotifyWhenFlapping
- Inherits:
-
God::Behavior
- Object
- God::Behavior
- God::Behaviors::NotifyWhenFlapping
- Defined in:
- lib/god/behaviors/notify_when_flapping.rb
Instance Attribute Summary collapse
-
#failures ⇒ Object
number of failures.
-
#notifier ⇒ Object
class to notify with.
-
#seconds ⇒ Object
number of seconds.
Attributes inherited from God::Behavior
Instance Method Summary collapse
- #before_restart ⇒ Object
- #before_start ⇒ Object
-
#initialize ⇒ NotifyWhenFlapping
constructor
A new instance of NotifyWhenFlapping.
- #valid? ⇒ Boolean
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
#initialize ⇒ NotifyWhenFlapping
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
#failures ⇒ Object
number of failures
5 6 7 |
# File 'lib/god/behaviors/notify_when_flapping.rb', line 5 def failures @failures end |
#notifier ⇒ Object
class to notify with
7 8 9 |
# File 'lib/god/behaviors/notify_when_flapping.rb', line 7 def notifier @notifier end |
#seconds ⇒ Object
number of seconds
6 7 8 |
# File 'lib/god/behaviors/notify_when_flapping.rb', line 6 def seconds @seconds end |
Instance Method Details
#before_restart ⇒ Object
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_start ⇒ Object
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
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 |