Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sample resque.rake for workers on multiple servers
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
You can’t perform that action at this time.