作业无法加载:未初始化的常量,延迟作业和Rails 3

时间:2011-03-29 04:07:12

标签: ruby-on-rails ruby delayed-job

我正在尝试在我的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

1 个答案:

答案 0 :(得分:3)

对不起大家,似乎我只是忘了重启我的工作进程,因为我搞乱了autoload_paths。作为参考,上述安排应该有效。请记住用rake jobs:work启动一名新员工!