Class: Qmore::Reservers::Strategies::Sources::Background
- Inherits:
-
Object
- Object
- Qmore::Reservers::Strategies::Sources::Background
- Includes:
- Enumerable
- Defined in:
- lib/qmore/reservers/strategies/sources.rb
Overview
Background Queue source runs in a background thread to periodically update the queues available.
Instance Attribute Summary collapse
-
#delay ⇒ Object
readonly
Returns the value of attribute delay.
-
#delegate ⇒ Object
readonly
Returns the value of attribute delegate.
Instance Method Summary collapse
- #each(&block) ⇒ Object
-
#initialize(delegate, delay) ⇒ Background
constructor
A new instance of Background.
-
#start ⇒ Thread
Spawns a thread to periodically update the queues.
- #stop ⇒ Object
Constructor Details
#initialize(delegate, delay) ⇒ Background
Returns a new instance of Background.
25 26 27 28 |
# File 'lib/qmore/reservers/strategies/sources.rb', line 25 def initialize(delegate, delay) @delegate = delegate @delay = delay end |
Instance Attribute Details
#delay ⇒ Object (readonly)
Returns the value of attribute delay.
22 23 24 |
# File 'lib/qmore/reservers/strategies/sources.rb', line 22 def delay @delay end |
#delegate ⇒ Object (readonly)
Returns the value of attribute delegate.
22 23 24 |
# File 'lib/qmore/reservers/strategies/sources.rb', line 22 def delegate @delegate end |
Instance Method Details
#each(&block) ⇒ Object
53 54 55 |
# File 'lib/qmore/reservers/strategies/sources.rb', line 53 def each(&block) @queues.each { |q| block.call(q) } end |
#start ⇒ Thread
Spawns a thread to periodically update the queues.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/qmore/reservers/strategies/sources.rb', line 33 def start @stop = false @queues = delegate.to_a Thread.new do begin loop do sleep delay break if @stop @queues = delegate.to_a end rescue => e retry end end end |
#stop ⇒ Object
49 50 51 |
# File 'lib/qmore/reservers/strategies/sources.rb', line 49 def stop @stop = true end |