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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/base/worker_bin.rb', line 26
def start
config_file = default_config_file
OptionParser.new do |opts|
opts.banner = "Usage: #{$0.split(/\//)[-1]} [options]"
opts.on("-c", "--config [ARG]", "Configuration File") do |opt|
config_file = opt
end
opts.on("-h", "--help", "Help") do
puts opts
exit
end
end.parse!
begin
config = YAML.load_file(config_file)
rescue => e
puts "Could not read configuration file: #{e}"
exit
end
required_opts = %w(resque)
missing_opts = required_opts.select {|o| !config.has_key? o}
raise ArgumentError, "Missing options: #{missing_opts.join(', ')}" unless missing_opts.empty?
logging_config = Steno::Config.from_hash(config["logging"])
Steno.init(logging_config)
redis_config = config["resque"]
logger = Steno.logger(config["node_id"])
redis_config = %w(host port password).inject({}){|res, o| res[o.to_sym] = config["resque"][o]; res}
AsyncJob::Config.redis_config = redis_config
AsyncJob::Config.logger = logger
ENV['WORKER_CONFIG'] = Yajl::Encoder.encode(config)
queues = (config["queues"] || config["node_id"]).split(',')
worker = Resque::Worker.new(*queues)
worker.verbose = config["resque_worker_logging"]
pid_file = ENV['PIDFILE']
raise "worker need PIDFILE env var." unless pid_file
File.open(pid_file, "w") {|f| f << worker.pid}
logger.info("Starting worker: #{worker}")
worker.work(config["interval"]||5)
end
|