Class: God::Conditions::DegradingLambda
- Inherits:
-
PollCondition
- Object
- Behavior
- God::Condition
- PollCondition
- God::Conditions::DegradingLambda
- Defined in:
- lib/god/conditions/degrading_lambda.rb
Overview
This condition degrades its interval by a factor of two for 3 tries before failing
Instance Attribute Summary collapse
-
#lambda ⇒ Object
Returns the value of attribute lambda.
Attributes inherited from PollCondition
Attributes inherited from God::Condition
#info, #notify, #phase, #transition
Attributes inherited from Behavior
Instance Method Summary collapse
-
#initialize ⇒ DegradingLambda
constructor
A new instance of DegradingLambda.
- #test ⇒ Object
- #valid? ⇒ Boolean
Methods inherited from PollCondition
Methods inherited from God::Condition
#friendly_name, generate, valid?
Methods inherited from Behavior
#after_restart, #after_start, #after_stop, #before_restart, #before_start, #before_stop, #friendly_name, generate
Methods included from God::Configurable
#base_name, complain, #complain, #friendly_name, #prepare, #reset
Constructor Details
#initialize ⇒ DegradingLambda
Returns a new instance of DegradingLambda.
9 10 11 12 |
# File 'lib/god/conditions/degrading_lambda.rb', line 9 def initialize super @tries = 0 end |
Instance Attribute Details
#lambda ⇒ Object
Returns the value of attribute lambda.
7 8 9 |
# File 'lib/god/conditions/degrading_lambda.rb', line 7 def lambda @lambda end |
Instance Method Details
#test ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/god/conditions/degrading_lambda.rb', line 20 def test puts "Calling test. Interval at #{interval}" @original_interval ||= interval if pass? @tries = 0 self.interval = @original_interval else if @tries == 2 self.info = 'lambda condition was satisfied' return true end self.interval = interval / 2.0 @tries += 1 end self.info = 'lambda condition was not satisfied' false end |
#valid? ⇒ Boolean
14 15 16 17 18 |
# File 'lib/god/conditions/degrading_lambda.rb', line 14 def valid? valid = true valid &= complain("Attribute 'lambda' must be specified", self) if self.lambda.nil? valid end |