Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Tree: 6d78e4ca98
Fetching contributors…

Cannot retrieve contributors at this time

executable file 61 lines (47 sloc) 1.779 kB
#!/usr/bin/env ruby
PACKET_LIB_PATH = File.expand_path(File.dirname(__FILE__))
["lib"].each { |x| $LOAD_PATH.unshift(File.join(PACKET_LIB_PATH,"..",x))}
require "packet"
module Packet
class WorkerRunner
include Packet::NbioHelper
def initialize args
cmd_args = args.split(':')
worker_name = cmd_args[2]
initial_arg_data_length = cmd_args[3].to_i
@worker_root = cmd_args[4]
@worker_load_env = cmd_args[5]
@worker_read_fd = UNIXSocket.for_fd(cmd_args[0].to_i)
@worker_write_fd = UNIXSocket.for_fd(cmd_args[1].to_i)
initial_arg_data = @worker_read_fd.read(initial_arg_data_length)
Packet::WorkerRunner.const_set(:WORKER_OPTIONS,Marshal.load(initial_arg_data))
require @worker_load_env if @worker_load_env && !@worker_load_env.empty?
load_worker worker_name
end
def load_worker(worker_name, worker_require=worker_name)
if @worker_root && (File.file? "#{@worker_root}/#{worker_require}.rb")
require "#{@worker_root}/#{worker_require}"
else
require worker_require
end
worker_klass = packet_classify(worker_name)
if worker_klass.is_worker?
worker_klass.start_worker(:read_end => @worker_read_fd,:write_end => @worker_write_fd,:options => WORKER_OPTIONS)
else
raise Packet::InvalidWorker.new(worker_name)
end
rescue LoadError => e
if worker_require.include?('/')
new_worker_require = worker_require.split("/")[0..-2].join("/")
load_worker(worker_name, new_worker_require)
return
end
puts "LoadError: #{e.message}"
raise e
rescue => e
puts "[load_worker] something went wrong: #{e.inspect}"
raise
end
end
end
Packet::WorkerRunner.new(ARGV[0])
Jump to Line
Something went wrong with that request. Please try again.