Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sidekiq without Rails doesn't load worker classes

Tags:

ruby

sidekiq

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(', ')}"
  end
end

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?

like image 471
PJSCopeland Avatar asked Jun 11 '14 03:06

PJSCopeland


People also ask

How do I manually run a Sidekiq job?

To run sidekiq, you will need to open a terminal, navigate to your application's directory, and start the sidekiq process, exactly as you would start a web server for the application itself. When the command executes you will see a message that sidekiq has started.

Should I use Activejob Sidekiq?

If you build a web application you should minimize the amount of time spent responding to every user; a fast website means a happy user.

Is Sidekiq multithreaded?

At the same time, Sidekiq uses multithreading so it is much more memory-efficient than Rescue.


1 Answers

So...

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

not

$ sidekiq -r sidekiq_script.rb

Well I feel slightly stupid for that.

like image 156
PJSCopeland Avatar answered Nov 06 '22 05:11

PJSCopeland