Skip to content

Instantly share code, notes, and snippets.

@jeremybmerrill
Created August 10, 2012 22:40
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremybmerrill/3318674 to your computer and use it in GitHub Desktop.
Save jeremybmerrill/3318674 to your computer and use it in GitHub Desktop.
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