Class: God::Conditions::Tries
- Inherits:
-
PollCondition
- Object
- Behavior
- God::Condition
- PollCondition
- God::Conditions::Tries
- Defined in:
- lib/god/conditions/tries.rb
Instance Attribute Summary collapse
-
#times ⇒ Object
Returns the value of attribute times.
-
#within ⇒ Object
Returns the value of attribute within.
Attributes inherited from PollCondition
Attributes inherited from God::Condition
#info, #notify, #phase, #transition
Attributes inherited from Behavior
Instance Method Summary collapse
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
Instance Attribute Details
#times ⇒ Object
Returns the value of attribute times.
5 6 7 |
# File 'lib/god/conditions/tries.rb', line 5 def times @times end |
#within ⇒ Object
Returns the value of attribute within.
5 6 7 |
# File 'lib/god/conditions/tries.rb', line 5 def within @within end |
Instance Method Details
#prepare ⇒ Object
7 8 9 |
# File 'lib/god/conditions/tries.rb', line 7 def prepare @timeline = Timeline.new(self.times) end |
#reset ⇒ Object
11 12 13 |
# File 'lib/god/conditions/tries.rb', line 11 def reset @timeline.clear end |
#test ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/god/conditions/tries.rb', line 21 def test @timeline << Time.now concensus = (@timeline.size == self.times) duration = self.within.nil? || (@timeline.last - @timeline.first) < self.within if within history = "[#{@timeline.size}/#{self.times} within #{(@timeline.last - @timeline.first).to_i}s]" else history = "[#{@timeline.size}/#{self.times}]" end if concensus && duration self.info = "tries exceeded #{history}" return true else self.info = "tries within bounds #{history}" return false end end |
#valid? ⇒ Boolean
15 16 17 18 19 |
# File 'lib/god/conditions/tries.rb', line 15 def valid? valid = true valid &= complain("Attribute 'times' must be specified", self) if self.times.nil? valid end |