作业无法加载:带有延迟的作业和Rails 3的未初始化常量 [英] Job failed to load: uninitialized constant with Delayed Job and Rails 3
问题描述
我正在尝试在Rails 3应用程序中使用延迟作业",但一直遇到障碍.作业不断失败,并显示以下错误: Job无法加载:未初始化的常量CrawlJob.
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.
我发现了其他几个SO线程,但没有遵循建议.这是相关的代码.
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
推荐答案
对不起,每个人似乎都因为忘记了autoload_paths而忘记了重新启动工作进程.供参考,上述安排应起作用.只要记住要使用 rake jobs:work
!
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
!
这篇关于作业无法加载:带有延迟的作业和Rails 3的未初始化常量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!