Class: Merb::Worker
Instance Attribute Summary collapse
-
#thread ⇒ Object
Returns the value of attribute thread.
Instance Method Summary collapse
-
#initialize ⇒ Worker
constructor
A new instance of Worker.
- #process_queue ⇒ Object
Constructor Details
#initialize ⇒ Worker
Returns a new instance of Worker.
6 7 8 |
# File 'lib/merb-core/dispatch/worker.rb', line 6 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 |
Instance Method Details
#process_queue ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/merb-core/dispatch/worker.rb', line 10 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 |