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!
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 called workers
):
% sidekiq -r ./workers/unique_job_worker.rb
If you have multiple workers, an option is to create a loader file to ensure everything is loaded.
load_workers.rb
($LOAD_PATH << 'workers').uniq!
require 'unique_job_worker'
require 'other_worker'
...
Then require the loader file on the command line:
% sidekiq -r ./load_workers.rb