Class: QueueWorker
- Inherits:
-
Object
- Object
- QueueWorker
- Defined in:
- lib/yodel/task_queue/queue_worker.rb
Constant Summary collapse
- PAUSE_DURATION =
1
Instance Method Summary collapse
-
#initialize(queue, stats_thread) ⇒ QueueWorker
constructor
A new instance of QueueWorker.
- #join ⇒ Object
- #kill ⇒ Object
- #run ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(queue, stats_thread) ⇒ QueueWorker
Returns a new instance of QueueWorker.
3 4 5 6 7 |
# File 'lib/yodel/task_queue/queue_worker.rb', line 3 def initialize(queue, stats_thread) @stats_thread = stats_thread @queue = queue run end |
Instance Method Details
#join ⇒ Object
29 30 31 |
# File 'lib/yodel/task_queue/queue_worker.rb', line 29 def join @thread.join end |
#kill ⇒ Object
25 26 27 |
# File 'lib/yodel/task_queue/queue_worker.rb', line 25 def kill @thread.kill end |
#run ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/yodel/task_queue/queue_worker.rb', line 9 def run @running = true @thread = Thread.new do while @running task = @queue.pop sleep(PAUSE_DURATION) and next if task.nil? task.execute @stats_thread.processed_task end end end |
#stop ⇒ Object
21 22 23 |
# File 'lib/yodel/task_queue/queue_worker.rb', line 21 def stop @running = false end |