Manage Laravel Queues using Supervisor

Every Laravel Queue has it's own cached version of Laravel Models, Jobs & Notification. You will be in serious panic if you are working on Jobs & Notification as Queue will not update the version of those file dynamically. You will need to restart Queue every time, by finding it in processes and killing it.

Supervisor is a client/server system that allows its users to control a number of processes on UNIX-like operating systems.

Install Supervisor using PIP

pip install supervisor

Create Supervisor & Queue Configuration Folder

mkdir /etc/supervisor
mkdir /etc/supervisor/conf.d

Generate Cnonfiguration

echo_supervisord_conf > /etc/supervisor/supervisord.conf

Edit Config with nano /etc/supervisor/supervisord.conf as below

file=/tmp/supervisor.sock   ; (the path to the socket file)

TO

file=/var/run/supervisor.sock   ; (the path to the socket file)

and

serverurl=unix:///tmp/supervisor.sock ; use a unix:// URL  for a unix socket

TO

serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL  for a unix socket

and

;[include]
;files = relative/directory/*.ini

TO

[include]
files = /etc/supervisor/conf.d/*.conf

Start Supervisor Service with Config

cd /etc/supervisor
supervisord -c supervisord.conf

Make sure you are not receiving any error when you run

supervisorctl status

Create new Queue

Create a Queue Configuration file

cd /etc/supervisor/conf.d
nano queue-worker-prod.conf
[program:queue-prod]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/html/project/artisan queue:work
autostart=true
autorestart=true
user=root
numprocs=1
redirect_stderr=true
stdout_logfile=/var/www/html/project/storage/logs/supervisord.log

Load the Queue Configuration

supervisorctl update

Check status of queues

supervisorctl status

Restart the Queue after Model / Job / Notification Updates

supervisorctl restart queue-prod:queue-prod_00

Find more help on http://supervisord.org

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.