docker-composelaravel-10laravel-queue

How to make supervisor work outside docker container for Laravel queue:worker


There's a lot of questions like this, feel like I've read them all and I'm no wiser.

Like everyone else I'm trying to have supervisor manage my Laravel queue for queued notifications.

If I'm outside my docker-container at my projects root and run: php /var/www/someproject/src/artisan queue:work --queue=mail-queue

I see:

Processing jobs from the [mail-queue] queue.

But nothing happens. Just hangs.

If I enter the container with sudo docker exec -it some_container /bin/bash and run:

php artisan queue:work --queue=mail-queue

It runs the jobs as expected as a lot of other questions/posts/answers/Laravel docs say. Great, it works in principle at least.

Obviously I'd like this to run in the background so I created a supervisor conf file like the docs say:

[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/some_project/src/artisan queue:work --queue=mail-queue --max-time=3600 --rest=0.4 --sleep=5
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=devops
numprocs=2
redirect_stderr=true
stdout_logfile=/home/devops/laravelworker.log
startsecs = 0
stopwaitsecs=3600

Running:

sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start "laravel-worker:*"

The two workers are running:

laravel-worker:laravel-worker_00   RUNNING   pid 76257, uptime 0:02:44
laravel-worker:laravel-worker_01   RUNNING   pid 76258, uptime 0:02:44

But no jobs are ran. Nothing in the log file at /home/devops/laravelworker.log.

The command in the supervisor config file doesn't work outside the container anyway. I tried changing that to:

command=php artisan queue:work --queue=mail-queue

Which unsurprisingly didn't work and added artisan can not be found to the logs.

I then changed the supervisor command to be:

command=docker exec -it come_container /bin/bash php artisan queue:work --queue=mail-queu

which results in the log having: the input device is not a TTY.

What am I doing wrong?

Why does it only run jobs if I exec into the container and how can I do this automatically.

Happy to show docker-compose/Dockerfile if it helps.


Solution

  • I got this working. Was a combination of things.

    Jobs started working, deleted from database and emails being sent