Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get sidekiq to execute a job immediately

Tags:

ruby

sidekiq

At the moment, I have a sidekiq job like this:

class SyncUser   include Sidekiq::Worker    def perform(user_id)     #do stuff   end end 

I am placing a job on the queue like this:

SyncUser.perform_async user.id 

This all works of course but there is a bit of a lag between calling perform_async and the job actually getting executed.

Is there anything else I can do to tell sidekiq to execute the job immediately?

like image 538
dagda1 Avatar asked Oct 08 '13 15:10

dagda1


People also ask

How do I manually run a Sidekiq job?

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 get a job on Sidekiq?

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.

How many jobs can Sidekiq handle?

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.


1 Answers

There are two questions here.

If you want to execute a job immediately, in the current context you can use:

SyncUser.new.perform(user.id) 

If you want to decrease the delay between asynchronous work being scheduled and when it's executed in the sidekiq worker, you can decrease the poll_interval setting:

Sidekiq.configure_server do |config|   config.poll_interval = 2 end 

The poll_interval is the delay within worker backends of how frequently workers check for jobs on the queue. The average time between a job being scheduled and executed with a free worker will be poll_interval / 2.

like image 115
Winfield Avatar answered Sep 19 '22 13:09

Winfield