class God::Conditions::GrowingQueue
Condition Symbol :growing_queue Type: Poll
Trigger when a queue is growing
Parameters Required
+obj+ is an instance of a queue interface class
Optional
+method+ is the method to call, it defaults to queue_size
Examples
Trigger if the queue has grown 3 out of the last 5 checks
restart.condition(:growing_queue) do |c|
c.times = [3,5] c.interval = 30.seconds c.obj = MyClass.new
end
Attributes
meth[RW]
obj[RW]
times[RW]
Public Class Methods
new()
click to toggle source
Calls superclass method
# File lib/growing_queue_condition/base.rb, line 27 def initialize super self.times ||= [2, 3] self.meth ||= :queue_size end
Public Instance Methods
prepare()
click to toggle source
# File lib/growing_queue_condition/base.rb, line 34 def prepare if self.times.kind_of? Integer self.times = [self.times, self.times] end @timeline = Timeline.new(self.times[1]) end
reset()
click to toggle source
# File lib/growing_queue_condition/base.rb, line 43 def reset @timeline.clear end
test()
click to toggle source
# File lib/growing_queue_condition/base.rb, line 55 def test failing = false count = obj.call(meth) num_of_fails = times[0] num_of_tests = times[1] @timeline.push count.to_i history = "[#{@timeline.join(', ')}]" if @timeline.length < num_of_tests self.info = 'not enough info' return false end ary = @timeline.dup.flatten fails = [] (num_of_fails == num_of_tests ? num_of_fails-1 : num_of_fails).times do if ary[-1] == 0 fails << false else fails << (ary[-1] >= ary[-2]) end ary.shift end bad, good = fails.partition { |f| TrueClass === f } failing = bad.length >= num_of_fails if failing self.info = "count increasing: (#{bad.length} fails #{history}" return true else self.info = "count ok: #{history}" return false end end
valid?()
click to toggle source
# File lib/growing_queue_condition/base.rb, line 48 def valid? valid = true valid &= complain("Attribute 'obj' must be specified", self) if self.obj.nil? valid end