How to set up your workers and make sure they restart after each deployment
This article assumes that you’ve already created a Laravel application with Moss and that you’re familiar with basic concepts about workers.
Set up your worker
Head to your Laravel site in Moss. Select the Workers tab and then click New worker.
Provide the following input:
- The command you need to run, e.g.
php artisan queue:work. Look at the documentation of your version of Laravel to check the command you must run.
- The number of processes that must run simultaneously. Moss sets up Supervisor so that it guarantees that you’re running as many processes as you provide here. Set as many processes as jobs you want to handle concurrently.
Click Create and Moss will launch an operation to set up your new worker. Now you can keep adding workers or click Close.
Once the operation ends, your worker will be up and running, as you can check if you log into your server:
ssh [email protected]<server-ip>
[email protected]<server>:~$ sudo supervisorctl daemon-node-exporter:daemon-node-exporter_00 RUNNING pid 12651, uptime 0:02:18worker-app-ab4cf5129d69439a82e260e544f4b721:worker-app-ab4cf5129d69439a82e260e544f4b721_00 RUNNING pid 12652, uptime 0:02:18supervisor> exit
You can also check that there’s a log file for the worker you’ve just set up:
<site-user>@<server>:~$ ls /home/<site-user>/sites/<site-name>/logs/workers/
Set up your deployment
Your worker is up and running 💪. But when deploying a new version of your application, you’ll likely want to restart your workers to make them use such version too, as the Laravel documentation describes.
To do this just head to the Deployments tab of your site, Deployment Flow section, and edit the post-activation script to include the command
php artisan queue:restart (or an equivalent one according to your Laravel version). Click Update and your next deployment will restart the related workers.