没有Rails的Sidekiq不会加载工作类

时间:2014-06-11 03:06:30

标签: ruby sidekiq

我正在使用Sidekiq 3.1.2 不带Rails

$ sidekiq -vr sidekiq.rb

sidekiq.rb看起来像这样:

($LOAD_PATH << '.' << 'lib' << 'lib/workers').uniq!
require 'lookup_worker'

lib / workers / lookup_worker.rb看起来像这样:

require 'sidekiq'

class LookupWorker
  include Sidekiq::Worker

  def perform(*args)
    puts "LookupWorker#perform fired with arguments #{args.map(&:inspect).join(', ')}"
  end
end

但是当我在irb并尝试

> LookupWorker.perform_async('asdf')

它给了我这个:

WARN: {"retry"=>true, "queue"=>"default", "class"=>"LookupWorker", "args"=>["asdf"], "jid"=>"8c278868c5f05ec9beb1dbae", "enqueued_at"=>1402457226.9612548}
WARN: uninitialized constant LookupWorker
WARN: [backtrace, none of it from my code]
ERROR: Sidekiq::Processor crashed!
NameError: uninitialized constant LookupWorker

我错过了什么?

1 个答案:

答案 0 :(得分:15)

因此...

LookupWorker require中,sidekiq宝石与第1行脚本sidekiq之间的混淆。

我的sidekiq.rb需要重命名为sidekiq_script.rb(或其他任何内容)。只有陷阱,我必须在运行sidekiq时包含目录:

$ sidekiq -r ./sidekiq_script.rb

$ sidekiq -r sidekiq_script.rb

我觉得这有点愚蠢。