unique_job_worker.rb
# -*- encoding : utf-8 -*-
require_relative 'logging_helper'
class UniqueJobWorker
include Sidekiq::Worker
include WorkerHelper
sidekiq_options retry: false,
backtrace: true,
queue: :sender,
failures: true
def perform(worker,campaign_guid, queue)
require'pry';binding.pry
end
end
unique_job_worker_test.rb
require 'test_helper'
require 'mocha/setup'
class UniqueJobWorkerTest < ActiveSupport::TestCase
def setup
require'pry';binding.pry
@worker = UniqueJobWorker.new
end
test "it exists" do
assert @worker
end
end
When enqueued through redis I get this response
INFO -- : Exception: uninitialized constant UniqueJobWorker
Any suggestions as to why my newly created worker, UniqueJobWorker, is not being found during runtime through redis or through a simple test?
Thanks ahead of time!
2
Answers
When you use sidekiq outside of Rails, you need to use the
-r
option to tell it how to load your workers. So (assuming that your worker is in a sub-directory calledworkers
):If you have multiple workers, an option is to create a loader file to ensure everything is loaded.
load_workers.rb
Then require the loader file on the command line:
I had the same issue and ended up being a Redis namespace issue:
https://github.com/mperham/sidekiq/issues/2834#issuecomment-184800981
Adding that fixed it for me:
You also need the
redis-namespace
gem BTW