Job failed to load: uninitialized constant with Delayed Job and Rails 3

 ̄綄美尐妖づ 提交于 2021-01-28 04:52:52

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!