Created
August 10, 2012 22:40
-
-
Save jeremybmerrill/3318674 to your computer and use it in GitHub Desktop.
Sample resque.rake for workers on multiple servers
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
require 'resque/tasks' | |
require 'resque_scheduler' | |
require 'resque_scheduler/tasks' | |
require 'resque_scheduler/server' | |
rails_root = ENV['RAILS_ROOT'] || File.dirname(__FILE__) + '/../..' | |
rails_env = ENV['RAILS_ENV'] || 'development' | |
resque_config = YAML.load_file(rails_root + '/config/resque.yml') #contains Redis's location on the network for different Rails environments | |
Resque.redis = resque_config[rails_env] | |
namespace :resque do | |
task :setup => :environment do | |
Resque.before_fork do |job| | |
# we need $extractor to be built before the following four jobs can be run, but, since it's expensive, | |
# we only want to rebuild it if necessary, and not on every fork. | |
if [BaseJob, PhotostreamJob, RegularPhotoJob, ReanalyzeJob].include? job.payload_class | |
if ! $extractor | |
puts "Must rebuild extractor in parent" | |
$extractor = Extractor.new | |
puts "Extractor built in parent" | |
end | |
end | |
end | |
Resque.schedule = YAML.load_file(File.expand_path('../resque_schedule.yml',__FILE__)) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment