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.
8 9 10 11 |
# File 'lib/god/conditions/degrading_lambda.rb', line 8 def initialize super @tries = 0 end |
Instance Attribute Details
#lambda ⇒ Object
Returns the value of attribute lambda.
6 7 8 |
# File 'lib/god/conditions/degrading_lambda.rb', line 6 def lambda @lambda end |
Instance Method Details
#test ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/god/conditions/degrading_lambda.rb', line 19 def test puts "Calling test. Interval at #{self.interval}" @original_interval ||= self.interval unless pass? if @tries == 2 self.info = "lambda condition was satisfied" return true end self.interval = self.interval / 2.0 @tries += 1 else @tries = 0 self.interval = @original_interval end self.info = "lambda condition was not satisfied" false end |
#valid? ⇒ Boolean
13 14 15 16 17 |
# File 'lib/god/conditions/degrading_lambda.rb', line 13 def valid? valid = true valid &= complain("Attribute 'lambda' must be specified", self) if self.lambda.nil? valid end |