Class: RQ::SleepCycle

Inherits:
Array
  • Object
show all
Defined in:
lib/rq/sleepcycle.rb

Overview

the sleepcycle class provides timeouts for better than average polling performance by the locking protocol used by the QDB

Instance Attribute Summary collapse

Attributes included from Fieldable

#fieldset

Instance Method Summary collapse

Methods inherited from Array

fields

Methods included from Fieldable

#fields, #fields=

Constructor Details

#initialize(min, max, inc) ⇒ SleepCycle

Returns a new instance of SleepCycle.

Raises:

  • (RangeError)


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

#incObject (readonly)

Returns the value of attribute inc.



16
17
18
# File 'lib/rq/sleepcycle.rb', line 16

def inc
  @inc
end

#maxObject (readonly)

Returns the value of attribute max.



14
15
16
# File 'lib/rq/sleepcycle.rb', line 14

def max
  @max
end

#minObject (readonly)

–{{{



13
14
15
# File 'lib/rq/sleepcycle.rb', line 13

def min
  @min
end

#rangeObject (readonly)

Returns the value of attribute range.



15
16
17
# File 'lib/rq/sleepcycle.rb', line 15

def range
  @range
end

Instance Method Details

#nextObject

–}}}



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

#resetObject

–}}}



36
37
38
39
40
# File 'lib/rq/sleepcycle.rb', line 36

def reset
#--{{{
  @idx = 0
#--}}}
end