Created
January 24, 2011 03:13
-
-
Save mattetti/792767 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
desc "Start the resque web interface" | |
task "resque:web" do | |
`rake isolate:sh['resque-web']` | |
end | |
# Task used to preload what's needed for the workers to run properly | |
task "resque:setup" do | |
require File.expand_path(File.join(File.dirname(__FILE__), "../../loaders/gem_sandboxing")) | |
require File.expand_path(File.join(File.dirname(__FILE__), "../../loadpath_initializer")) | |
require File.expand_path('../../../core/loaders/console_initializer', File.dirname(__FILE__)) | |
puts "Master worker pid: #{Process.pid}" | |
end | |
desc "Start resque workers in the bg: $ RQUEUES='Q1,Q2;*' rake start_resque_workers" | |
task :start_resque_workers do | |
require 'resque/tasks' | |
queues = ENV['RQUEUES'] || '*' | |
ENV['INTERVAL'] = '1' | |
ENV['VERBOSE'] = '1' | |
# replaced the following shell out command by Ruby code: | |
# `INTERVAL=1 QUEUE=#{queue} VERBOSE=1 nohup rake resque:work > #{worker_log} &` | |
workers = [] | |
# creating a worker per queue list delimited by a semi colon | |
queues.split(';').each_with_index do |q, idx| | |
queue = q.strip | |
log_path = File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'log')) | |
worker_log = "#{log_path}/resque_worker_#{idx}_#{queue}.log" | |
pid = fork do | |
# redirecting stdout to our log file. | |
$stdout = File.new(worker_log, 'w') | |
puts "#{Time.now} Working on queue: #{queue}\n" | |
ENV['QUEUE'] = queue | |
Rake::Task['resque:work'].invoke | |
end | |
puts "forked a worker (queue: #{queue}) with pid: #{pid}" | |
puts "logging to #{worker_log}\n" | |
workers << pid | |
end | |
# detaching each fork so the launcher process can exit | |
# you can change the code here if you want to keep track of each worker's pid | |
workers.each{|pid| Process.detach(pid) } | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment