Class: QueueLite::Worker
- Inherits:
-
Object
- Object
- QueueLite::Worker
- Defined in:
- lib/queue_lite/worker.rb
Instance Method Summary collapse
-
#initialize(queue) ⇒ Worker
constructor
A new instance of Worker.
- #perform_once ⇒ Object
- #run ⇒ Object
- #shutdown ⇒ Object
Constructor Details
#initialize(queue) ⇒ Worker
Returns a new instance of Worker.
7 8 9 10 |
# File 'lib/queue_lite/worker.rb', line 7 def initialize(queue) @queue = queue @running = false end |
Instance Method Details
#perform_once ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/queue_lite/worker.rb', line 19 def perform_once task = queue.pop return if task.nil? klass, *args = JSON.parse(task.data) begin Object.const_get(klass).perform(*args).tap do queue.done(task.id) end rescue queue.failed(task.id) end end |
#run ⇒ Object
12 13 14 15 16 17 |
# File 'lib/queue_lite/worker.rb', line 12 def run @running = true while @running perform_once end end |
#shutdown ⇒ Object
33 34 35 |
# File 'lib/queue_lite/worker.rb', line 33 def shutdown @running = false end |