skip to Main Content

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


  1. 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
    
    Login or Signup to reply.
  2. 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:

    config.redis = {
        url: ENV['REDIS_URL'],
        namespace: "some_namespace_different_for_each_app"
    }
    

    You also need the redis-namespace gem BTW

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search