Sidekiq worker not getting triggered

2019-02-12 01:12发布

问题:

I am using Sidekiq for my background jobs:

I have a worker app/workers/data_import_worker.rb

class DataImportWorker
 include Sidekiq::Worker
 sidekiq_options retry: false

  def perform(job_id,file_name)
    begin
    #Some logic in it .....
  end
 end

Called from a file lib/parse_excel.rb

  def parse_raw_data
      #job_id and #filename are defined bfr
      DataImportWorker.perform_async(job_id,filename)   
  end

As soon as i trigger it from my action the worker is not getting called.. Redis is running on localhost:6379

Any idea why this must be happening. The Environment is Linux.

回答1:

I had a similar problem where Sidekiq was running but when I called perform_async it didn't do anything except return true.

The problem was rspec-sidekiq was added to my ":development, :test" group. I fixed the problem by moving rspec-sidekiq to the ":test" group only.



回答2:

Start sidekiq from the root directory of your Rails app. For example,

bundle exec sidekiq -e staging -C config/sidekiq.yml



回答3:

I encounter the same problem, it turns out that the argument I've passed in the function perform_async is not appropriate, it seems that one should not pass any query result in perform_async, you must do all the query in the function perform.



回答4:

You need to specify the name of the queue that worker is for.

Example: sidekiq_options retry: false, :queue => data_import_worker

data_import_worker can be any name you want to give it.

Then when you go to the web interface: yoursite.com/sidekiq, you'll be able to see the current workers for the queue "data_import_worker"



回答5:

For me when doing a perform_later, it would enqueue but never remove from queue. I needed to add my queue name to the sidekiq.yml file

---
:concurrency: 25
:pidfile: ./tmp/pids/sidekiq.pid
:logfile: ./log/sidekiq.log
:queues:
  - default
  - my_queue


回答6:

Lost a good 15 min on this. To check if Sidekiq is correctly loading your config file (with the queues names), go to the web interface in the Busy tab and you'll find your Process ID and below it you'll find your queues.

In our case, we had misspelled mailer (the correct ActiveJob queue for Mailers is mailers, in plural).



回答7:

My issue was simply having the worker file in the wrong path.

Needs to be in "project_root/app/worker/worker.rb", not "project_root/worker/worker.rb"

Check the file path!



回答8:

is it realy run multiple workers on standalone sidekiq? for example I have 2 workers: ProccessWorker CallbackWorker

when I am runnigs sidekiq: bundle exec sidekiq -r ./workers/proccess_worker.rb -C ./config/sidekiq.yml

only one worker in same time.



回答9:

I was calling perform_async(23) in a production console, however my sidekiq was started in staging mode.

After I started the Sidekiq in production mode, things have started working very well.