我正在尝试在我的Rails 3应用程序中使用延迟作业,但仍然遇到障碍。作业因错误而失败:Job failed to load: uninitialized constant CrawlJob.
我发现了其他一些SO线程,并在那里遵循建议无济于事。这是相关的代码。
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
答案 0 :(得分:3)
对不起大家,似乎我只是忘了重启我的工作进程,因为我搞乱了autoload_paths。作为参考,上述安排应该有效。请记住用rake jobs:work
启动一名新员工!