Class: Merb::Worker
Instance Attribute Summary collapse
-
#thread ⇒ Object
Returns the value of attribute thread.
Class Method Summary collapse
-
.start ⇒ Object
private
Returns Merb::Worker:: instance of a worker.
Instance Method Summary collapse
-
#initialize ⇒ Worker
constructor
private
Creates a new worker thread that loops over the work queue.
-
#process_queue ⇒ Object
private
Processes tasks in the Merb::Dispatcher.work_queue.
Constructor Details
#initialize ⇒ Worker
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates a new worker thread that loops over the work queue.
17 18 19 |
# File 'lib/merb-core/dispatch/worker.rb', line 17 def initialize @thread = Thread.new { loop { process_queue } } end |
Instance Attribute Details
#thread ⇒ Object
Returns the value of attribute thread.
4 5 6 |
# File 'lib/merb-core/dispatch/worker.rb', line 4 def thread @thread end |
Class Method Details
.start ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns
- Merb::Worker
-
instance of a worker.
10 11 12 |
# File 'lib/merb-core/dispatch/worker.rb', line 10 def self.start new end |
Instance Method Details
#process_queue ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Processes tasks in the Merb::Dispatcher.work_queue.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/merb-core/dispatch/worker.rb', line 24 def process_queue begin while blk = Merb::Dispatcher.work_queue.pop # we've been blocking on the queue waiting for an item sleeping. # when someone pushes an item it wakes up this thread so we # immediately pass execution to the scheduler so we don't # accidentally run this block before the action finishes # it's own processing Thread.pass blk.call end rescue Exception => e Merb.logger.warn! %Q!Worker Thread Crashed with Exception:\n#{Merb.exception(e)}\nRestarting Worker Thread! retry end end |