Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How set timeout for jobs in sidekiq

I encountered an issue with sidekiq:
I want to set timeout for jobs, meaning when a job has process time greater than timeout then that job will stop.

I have searched how to set global timeout config in file sidekiq.yml.
But I want to set separate timeout for difference separate jobs meaning one of classes to define worker will have particular timeout config.
Can you help me.
Thanks so much.

like image 762
huyhoang-vn Avatar asked Feb 18 '16 06:02

huyhoang-vn


People also ask

How do you stop a Sidekiq worker?

Once a worker has started processing a job, you cannot stop it externally without shutting down the entire process. There is no safe way to stop a thread.

How many jobs can Sidekiq handle?

Sidekiq handles concurrency by using multiple threads in its process. This way, it can process multiple jobs at once, each thread processing one job at a time. By default, Sidekiq uses 10 threads per process. You can configure it to use more threads, thus increasing concurrency.

How does Sidekiq store jobs?

It uses Redis as an in-memory data structure to store all of its job and operational data. It's important to be aware that Sidekiq by default doesn't do scheduling, it only executes jobs. We can use job scheduling frameworks like Resque, which is also based on Redis.

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 schedule work in Sidekiq?

Scheduling in sidekiq is an enterprise level feature. If you don’t want to spend on that, this gem is for you. run bundle install every time you add a new gem. Then create a file called schedule.yml under the config directory. Inside that file, add the following: Here it says 5. It means it will perform the work in every 5 minute intervals.

How does Redis work with Sidekiq?

If you read the redis options doc here, there is a sidekiq server and sidekiq client, they are configured independently, The server is responsible for popping jobs off the queue (s) and executing them. The client is responsible for adding jobs to the queue. which matches the diagram above. There is another diagram here.

How many Sidekiq jobs can I run on one app?

you can also run 1 or more Sidekiqs per app, but note that if you have more than 1 Sidekiq worker server, you cannot guarantee the sequence of job execution. To get the sidekiq worker running, you can also run service with systemd, such as this sidekiq.service file here.


Video Answer


1 Answers

There's no approved way to do this. You cannot stop a thread safely while it is executing. You need to change your job to check periodically if it should stop.

You can set network timeouts on any 3rd party calls you are making so that they time out.

like image 144
Mike Perham Avatar answered Oct 09 '22 13:10

Mike Perham