Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sidekiq worker not getting triggered

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.

like image 659
AnkitG Avatar asked Oct 10 '12 09:10

AnkitG


People also ask

How do you run a Sidekiq worker?

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.

How do I test my Sidekiq worker?

To test your Sidekiq Worker jobs array, run WorkerNameHere.jobs in terminal and see if it contains your job with your jid. If it does, then it was enqueued in Sidekiq to be run as a job.

Is Sidekiq a FIFO?

Sidekiq reads jobs from a Redis queue, using the First In First Out (FIFO) model, to process jobs.

How many employees does Sidekiq have?

Today Sidekiq uses a default concurrency of 25. These means Sidekiq will spawn 25 worker threads and execute up to 25 jobs concurrently in a process.

Why does my Sidekiq worker class run for a long time?

I have a Sidekiq worker class that run for a duration which can be quite long sometimes. Jobs and job states are persisted in database records. Sometimes worker processes are restarted due to code release. The job record has an attribute for job state and it's "stuck" on "started" when the the job is interrupted due to worker process terminated.

Why does Sidekiq raise an exception when a job fails?

It was happening because Sidekiq captures any exception occurred in a job (that’s how it decides that a job failed) and uses it to retry failed jobs. It doesn’t raise after capture unless retries are exhausted which will happen after a lot of retries (you can configure retry policy).

Is Sidekiq a good background job processing solution?

Sidekiq is famous (in the Ruby world) as an easy and simple background job processing solution. Sidekiq covers almost all the use cases that you expect from a background job processing solution but sometimes you need something that is not supported out of the box.


2 Answers

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.

like image 198
basgys Avatar answered Oct 05 '22 23:10

basgys


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

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

like image 21
Ranjithkumar Ravi Avatar answered Oct 06 '22 00:10

Ranjithkumar Ravi