【问题标题】:uninitialized constant while calling ImageWorker in sidekiq在 sidekiq 中调用 ImageWorker 时未初始化的常量
【发布时间】:2012-11-05 05:38:23
【问题描述】:

在我的Banner 模型中,我称之为:

after_save :enqueue_image   

  def enqueue_image
    ImageWorker.perform_async(id, key) if key.present?
  end

class ImageWorker
  include Sidekiq::Worker

  def perform(id, key)
    banner = Banner.find(id)
    banner.key = key
    banner.remote_image_url = banner.image.direct_fog_url(with_path: true)
    banner.save!
  end
end

我在sidekiq 中遇到的错误是:

2012-11-16T12:30:35Z 75701 TID-ows7fyu3w WARN: {"retry"=>true, "queue"=>"default", "class"=>"Banner::ImageWorker", "args"=>[6, "uploads/af-64b9e8b8c96a/770x350.gif"], "jid"=>"b8f23a2387f2b751"}
2012-11-16T12:30:35Z 75701 TID-ows7fyu3w WARN: uninitialized constant Banner::ImageWorker
2012-11-16T12:30:35Z 75701 TID-ows7fyu3w WARN: /.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.8/lib/active_support/inflector/methods.rb:230:in `block in constantize'
/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.8/lib/active_support/inflector/methods.rb:229:in `each'
/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.8/lib/active_support/inflector/methods.rb:229:in `constantize'
/.rvm/gems/ruby-1.9.3-p194@myapp/gems/activesupport-3.2.8/lib/active_support/core_ext/string/inflections.rb:54:in `constantize'
/.rvm/gems/ruby-1.9.3-p194@myapp/gems/sidekiq-2.5.3/lib/sidekiq/processor.rb:37:in `block in process'
/.rvm/gems/ruby-1.9.3-p194@myapp/gems/celluloid-0.12.3/lib/celluloid/calls.rb:57:in `call'
/.rvm/gems/ruby-1.9.3-p194@myapp/gems/celluloid-0.12.3/lib/celluloid/calls.rb:57:in `dispatch'
/.rvm/gems/ruby-1.9.3-p194@myapp/gems/celluloid-0.12.3/lib/celluloid/future.rb:18:in `block in initialize'
/.rvm/gems/ruby-1.9.3-p194@myapp/gems/celluloid-0.12.3/lib/celluloid/internal_pool.rb:48:in `call'
/.rvm/gems/ruby-1.9.3-p194@myapp/gems/celluloid-0.12.3/lib/celluloid/internal_pool.rb:48:in `block in create'

【问题讨论】:

  • 这是在 Rails 3 应用程序中。所以不需要 - 据我了解。
  • 您的横幅模型是否有可能在模块内命名?如果是这样,您需要为 ImageWorker 加上 ::ImageWorker 前缀,以便它知道查看该模块之外的内容。
  • 不。它只是一个普通的香草模型。 class Banner < ActiveRecord::Base
  • 你在class Banner < ActiveRecord::Base; end中使用class ImageWorker吗?
  • @SergeyKishenin 是的......这就是 class ImageWorker 被声明和使用的地方。

标签: ruby-on-rails ruby-on-rails-3 sidekiq


【解决方案1】:

我知道这是一个老问题,但因为遇到类似问题而偶然发现。

摆弄我发现了这个issue on github,这让我明白我做错了,并且让我的工作人员在 lib 文件夹中。

将它移动到工作文件夹解决了这个问题。

【讨论】:

    【解决方案2】:

    我在运行多个 sidekiq 进程时遇到了这个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多