Class: God::Conditions::DegradingLambda

Inherits:
PollCondition show all
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

Attributes inherited from PollCondition

#interval

Attributes inherited from God::Condition

#info, #notify, #phase, #transition

Attributes inherited from Behavior

#watch

Instance Method Summary collapse

Methods inherited from PollCondition

#after, #before

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

#initializeDegradingLambda

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

#lambdaObject

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

#testObject



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

Returns:

  • (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