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.
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.
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.
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.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With