PJSCopeland PJSCopeland - 1 year ago 173
Ruby Question

Sidekiq without Rails doesn't load worker classes

I'm using Sidekiq 3.1.2 without Rails like this:

$ sidekiq -vr sidekiq.rb

sidekiq.rb looks like this:

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

lib/workers/lookup_worker.rb looks like this:

require 'sidekiq'

class LookupWorker
include Sidekiq::Worker

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

But when I'm in irb and try

> LookupWorker.perform_async('asdf')

it gives me this:

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

What am I missing?

Answer Source


In LookupWorker, require was getting confused between sidekiq the gem and sidekiq the script on line 1.

My sidekiq.rb needed to be renamed as sidekiq_script.rb (or anything else really). Only gotcha is, I have to include the directory when running sidekiq:

$ sidekiq -r ./sidekiq_script.rb


$ sidekiq -r sidekiq_script.rb

Well I feel slightly stupid for that.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download