Class: RQ::SleepCycle
Overview
the sleepcycle class provides timeouts for better than average polling performance by the locking protocol used by the QDB
Instance Attribute Summary collapse
-
#inc ⇒ Object
readonly
Returns the value of attribute inc.
-
#max ⇒ Object
readonly
Returns the value of attribute max.
-
#min ⇒ Object
readonly
–{{{.
-
#range ⇒ Object
readonly
Returns the value of attribute range.
Attributes included from Fieldable
Instance Method Summary collapse
-
#initialize(min, max, inc) ⇒ SleepCycle
constructor
A new instance of SleepCycle.
-
#next ⇒ Object
–}}}.
-
#reset ⇒ Object
–}}}.
Methods inherited from Array
Methods included from Fieldable
Constructor Details
#initialize(min, max, inc) ⇒ SleepCycle
Returns a new instance of SleepCycle.
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rq/sleepcycle.rb', line 17 def initialize min, max, inc #--{{{ @min, @max, @inc = Float(min), Float(max), Float(inc) @range = @max - @min raise RangeError, "max < min" if @max < @min raise RangeError, "inc > range" if @inc > @range s = @min push(s) and s += @inc while(s <= @max) self[-1] = @max if self[-1] < @max reset #--}}} end |
Instance Attribute Details
#inc ⇒ Object (readonly)
Returns the value of attribute inc.
16 17 18 |
# File 'lib/rq/sleepcycle.rb', line 16 def inc @inc end |
#max ⇒ Object (readonly)
Returns the value of attribute max.
14 15 16 |
# File 'lib/rq/sleepcycle.rb', line 14 def max @max end |
#min ⇒ Object (readonly)
–{{{
13 14 15 |
# File 'lib/rq/sleepcycle.rb', line 13 def min @min end |
#range ⇒ Object (readonly)
Returns the value of attribute range.
15 16 17 |
# File 'lib/rq/sleepcycle.rb', line 15 def range @range end |
Instance Method Details
#next ⇒ Object
–}}}
29 30 31 32 33 34 35 |
# File 'lib/rq/sleepcycle.rb', line 29 def next #--{{{ ret = self[@idx] @idx = ((@idx + 1) % self.size) ret #--}}} end |
#reset ⇒ Object
–}}}
36 37 38 39 40 |
# File 'lib/rq/sleepcycle.rb', line 36 def reset #--{{{ @idx = 0 #--}}} end |