开发者

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

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


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜