Sha256: a91bb2e3954d54a026977ce5c65a9817e6a215095752cd27e105178b14ba2e16

Contents?: true

Size: 806 Bytes

Versions: 10

Compression:

Stored size: 806 Bytes

Contents

module Merb
  class Worker
    
    attr_accessor :thread
    
    def initialize
      @thread = Thread.new { loop { process_queue } }
    end
    
    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
    
  end
end    

Version data entries

10 entries across 10 versions & 5 rubygems

Version Path
joe-merb-core-0.9.8 lib/merb-core/dispatch/worker.rb
wycats-merb-core-0.9.8 lib/merb-core/dispatch/worker.rb
wycats-merb-core-0.9.9 lib/merb-core/dispatch/worker.rb
thorero-0.9.4.5 lib/merb-core/dispatch/worker.rb
merb-core-0.9.4 lib/merb-core/dispatch/worker.rb
merb-core-0.9.5 lib/merb-core/dispatch/worker.rb
merb-core-0.9.7 lib/merb-core/dispatch/worker.rb
merb-core-0.9.6 lib/merb-core/dispatch/worker.rb
merb-core-0.9.8 lib/merb-core/dispatch/worker.rb
thorero-core-0.9.4.6 lib/merb-core/dispatch/worker.rb