Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Queue worker on Heroku

I'm running Laravel 5 on Heroku. I'm using the Laravel Queue for background tasks. What is/are the most reliable ways to listen to the queue and run it's jobs?

like image 996
Till Avatar asked Feb 27 '15 10:02

Till


4 Answers

Update: Deprecation notice

php artisan queue:work -h

--daemon    Run the worker in daemon mode (Deprecated)

Running queue:work spawns a daemon automatically. The flag is no longer required.


For me, it worked using Redis as the queue driver and setting up a queue worker process additionally to the web process.

My Procfile then looks like this:

web: vendor/bin/heroku-php-apache2 public/
worker: php artisan queue:work redis --sleep=3 --tries=3 --daemon

I don't really know if this is the way one should go, but it works for now.

Edit:

Note, that you are starting up another dyno here, so if you are not using the free tier on Heroku it's double the price now.

like image 89
eneskaya Avatar answered Oct 16 '22 13:10

eneskaya


Set config var in heroku like this (Laravel 5.6):

QUEUE_DRIVER=database

Or set config var in heroku like this (Laravel 5.7):

QUEUE_CONNECTION=database

To start the worker dyno in case it is not running

heroku ps:scale worker=1

Procfile looks like this: Note: specify the driver you want to use after queue:work

web: vendor/bin/heroku-php-apache2 public/
worker: php artisan queue:restart && php artisan queue:work database --tries=3

To view messages from the worker

heroku logs --ps worker

To tail messages from the worker

heroku logs --tail --ps worker
like image 43
Manford Benjamin Avatar answered Oct 16 '22 12:10

Manford Benjamin


If you are on the free plan on Heroku quite easy to get the worker process running for processing your queued items

To make sure you have both the worker and web dynos running

heroku ps:scale

To start the worker dyno in case it is not running

heroku ps:scale worker=1

Proc file looks like this:

worker: php artisan queue:restart && php artisan queue:work --tries=3

To view messages from the worker

heroku logs --ps worker
like image 32
Dele Avatar answered Oct 16 '22 12:10

Dele


I have found running the Queue Worker as a daemon Laravel docs works well when used with supervisord supervisor docs which will watch the process and restart it if it should fail for any reason.

Laravel Forge supports this out of the box and provides you with a GUI to setup the daemon and supervisor tasks, if that's something you'd prefer

like image 1
Ashley Evans Avatar answered Oct 16 '22 11:10

Ashley Evans