/usr/lib/ruby/1.8/merb-core/dispatch/worker.rb is in libmerb-core-ruby1.8 1.0.12+dfsg-4fakesync1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 | module Merb
class Worker
# :api: private
attr_accessor :thread
class << self
# ==== Returns
# Merb::Worker:: instance of a worker.
#
# :api: private
def start
@worker ||= new
Merb.at_exit do
if Merb::Dispatcher.work_queue.empty?
@worker.thread.abort_on_exception = false
@worker.thread.raise
else
@worker.thread.join
end
end
@worker
end
end
# Creates a new worker thread that loops over the work queue.
#
# :api: private
def initialize
@thread = Thread.new do
loop do
process_queue
break if Merb::Dispatcher.work_queue.empty? && Merb.exiting
end
end
end
# Processes tasks in the Merb::Dispatcher.work_queue.
#
# :api: private
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
break if Merb::Dispatcher.work_queue.empty? && Merb.exiting
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
|