问题
I'm trying to utilize Delayed Job in my Rails 3 app, but keep hitting a snag. The jobs keep failing with the error: Job failed to load: uninitialized constant CrawlJob.
I found a couple of other SO threads and followed advice there to no avail. Here is the relevant code.
Application.rb
require File.expand_path('../boot', __FILE__)
require 'rails/all'
...
module Decurate
class Application < Rails::Application
...
config.autoload_paths += %W(#{config.root}/lib)
config.autoload_paths += Dir["#{config.root}/lib/**/"]
...
end
end
/lib/crawl_job.rb
class CrawlJob < Struct.new(:merchant_id,:ec2,:s3)
def perform
...
end
end
/lib/tasks/cron.rake
merchants = Store.all.collect{ |store| store[:merchant_id] }
merchants.each do |merchant_id|
queue.push merchant_id
end
merchants.each do |merchant_id|
Delayed::Job.enqueue CrawlJob.new(merchant_id,@ec2,@s3)
end
回答1:
Sorry everyone, it seems that I simply forgot to restart my worker processes as I was messing with the autoload_paths. For reference, the above arrangement should work. Just remember to start up a new worker with rake jobs:work
!
来源:https://stackoverflow.com/questions/5467778/job-failed-to-load-uninitialized-constant-with-delayed-job-and-rails-3