- 11 months ago
- Zaid Bin Khalid
- 913 Views
-
3
To handle large file processing in an OMS (Order Management System), it is necessary to have the supervisor package installed on the live server. This package allows for the concurrent execution of multiple batch jobs.
Install Supervisor
Use the below command to install the supervisor on your Linux instance.
sudo apt-get install supervisor
Supervisor Configuration
sudo vi /etc/supervisor/conf.d/<batch_queue_name>_queue_worker.conf
The below script is a complete example of the supervisor config file, you need to create this file under /etc/supervisor/conf.d/ directory with the .conf extension.
[program:import_products]
process_name = %(program_name)s_%(process_num)02d
command=php /YOUR-PROJECT-PATH/artisan queue:work --queue=import_products --tries=3 --delay=3
autostart=true
autorestart=true
numprocs=1
redirect_stderr=true
stdout_logfile=/YOUR-PROJECT-LOG-PATH/storage/logs/queue-worker.log
Running the queue workers on Staging
On staging, if there are any changes in the config files, please run the commands below in sequence.
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start all
If Queue workers do not work as expected
Sometime we need to restart queues.
Since queue workers are long-lived processes, they will not notice changes to your code without being restarted. So, the simplest way to deploy an application using queue workers is to restart the workers during your deployment process. You may gracefully restart all of the workers by issuing the queue:
restart
command:
php artisan queue:restart
Running the queue workers locally
In your local environment, you need to keep the queue workers up and running one by one.
php artisan queue:work --queue=import_products
Local System setup
In your local system, you can set up and install the supervisor but for the queue process, you have to do the following things.
- Create Queue process tables
- Change the .env file
- Run the below commands on your local to test the process.
Create Queue process tables
First of all, you need to run the below commands to create the migration files to handle the Laravel queue processes. There are 3 main tables in this process so you have to create 3 migration files with the following commands.
Skip the below creation if you already have jobs, job_batches, and failed_jobs tables in your database.
php artisan queue:table
php artisan queue:batches-table
php artisan queue:failed-table
After creating the migration files just run the below command to execute the migrations.
Change the .env file
Change the driver for the queue process in your config file. Change sync to the database driver.
QUEUE_CONNECTION=database
Run the below commands on your local to test the process.
Finally, you only need to run the queue process with the help of a command. As I told you before there is a supervisor package that is responsible to manage all queue processes for you. But for local testing, you have to run the manual command.
php artisan queue:work --queue=import_products
- 11 months ago
- Zaid Bin Khalid
- 913 Views
-
3