When you deploy your laravel application in a live server or we can say when you start your application on production mode that time you need to keep some function running like a queue. So we need to hit a command for start queue:work for processing jobs. Sometimes queue:work process stops working or stops running on the server for a variety of many reasons, such as a exceeded worker timeout or overload server or maybe error during the perform queue job or in cash run queue:restart command.
For this reason, we need to monitor the queue:work configuration so when they stop working, exist, automatically restart itself by configuration supervision in the server.
Also, Supervision monitoring help to process the queue and allow you to run correctly on the server. So in this post, we will learn how to configure supervision on the server.
Supervision is the process monitor for the Linux operating system, that will allow you to restart the queue: and work automatically if fails by configuring it on the server.
To install supervision on ubuntu, you may use given following suggested command.
sudo apt-get install supervisor
Supervision configuration files may stored n the /etc/supervisor/conf.d directory. With this given direcotry. You may create any number of configuration files that instruct suervision how to process should work and monitioring. For example let us create a file for laravel-worker.conf that file start monitoring queue:work processes.
[program:laravel-worker] process_name=%(program_name)s_%(process_num)02d command=php /home/forge/app.com/artisan queue:work sqs --sleep=3 --tries=3 --max-time=3600 autostart=true autorestart=true stopasgroup=true killasgroup=true user=forge numprocs=8 redirect_stderr=true stdout_logfile=/home/forge/app.com/worker.log stopwaitsecs=3600
In cash queue:work fails it will automatically restart if fails. you can change the command option as per your desired work.
Note: You must ensure that the value of stopwaitsecs is greater than the given number of seconds consumed by your running jobs. Otherwise, Supervisor may kill the jobs before they finish processing.
Once you have done all the supervision configuration on the server, We need to update the supervision configuration on the server and start processes using the following suggest commands:
sudo supervisorctl reread sudo supervisorctl update sudo supervisorctl start laravel-worker:*
Once you press all the above-given commands it will start monitoring your queue:work jobs successfully.
We always thanks to you for reading our blogs.
Dharmesh Chauhan(Swapinfoway Founder)
We Are Also Recommending You :
- Import Export Database in JSON Format Laravel
- Laravel 10 Firebase Web Push Notification Tutorial
- How To Convert HTML To Image/PDF Using Snappy In Laravel 9
- How To Integrate Stripe Payment Gateway in Laravel 9
- Laravel pluck method example | Laravel Pluck
- Arr::accessible() | Laravel Helper Function
- Trying to access array offset on value of type int
- Arr::collapse() | Laravel Helper Function
- Laravel Livewire CRUD Using Bootstrap Modal Full Example Guideline And Demo Source Code
- Arr::forget() | Laravel Helper Function