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?
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.
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.
At the same time, Sidekiq uses multithreading so it is much more memory-efficient than Rescue.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With