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.
6 7 8 |
# File 'lib/god/conditions/tries.rb', line 6 def times @times end |
#within ⇒ Object
Returns the value of attribute within.
6 7 8 |
# File 'lib/god/conditions/tries.rb', line 6 def within @within end |
Instance Method Details
#prepare ⇒ Object
8 9 10 |
# File 'lib/god/conditions/tries.rb', line 8 def prepare @timeline = Timeline.new(times) end |
#reset ⇒ Object
12 13 14 |
# File 'lib/god/conditions/tries.rb', line 12 def reset @timeline.clear end |
#test ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/god/conditions/tries.rb', line 22 def test @timeline << Time.now consensus = (@timeline.size == times) duration = within.nil? || (@timeline.last - @timeline.first) < within history = if within "[#{@timeline.size}/#{times} within #{(@timeline.last - @timeline.first).to_i}s]" else "[#{@timeline.size}/#{times}]" end if consensus && duration self.info = "tries exceeded #{history}" true else self.info = "tries within bounds #{history}" false end end |
#valid? ⇒ Boolean
16 17 18 19 20 |
# File 'lib/god/conditions/tries.rb', line 16 def valid? valid = true valid &= complain("Attribute 'times' must be specified", self) if times.nil? valid end |