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.



9
10
11
12
# File 'lib/god/conditions/degrading_lambda.rb', line 9

def initialize
  super
  @tries = 0
end

Instance Attribute Details

#lambdaObject

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

#testObject



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

Returns:

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