When using Envoyer for zero-downtime deployments, the timing of running php artisan horizon:terminate is crucial to ensure that your workers are using the latest code without causing any downtime or inconsistencies.
Here's a recommended approach:
-
Clone New Release: This step is straightforward and doesn't require any action related to Horizon.
-
Install Composer Dependencies: Ensure all dependencies are up-to-date. This step is also independent of Horizon.
-
Terminate Horizon Before Activating New Release:
- Run
php artisan horizon:terminatebefore activating the new release. This ensures that Horizon will gracefully terminate and restart with the new code once the new release is activated. - By terminating Horizon before activation, you minimize the risk of processing jobs with outdated code. Horizon will automatically restart with the new release once it's activated.
- Run
-
Activate New Release:
- After terminating Horizon, proceed to activate the new release. This will ensure that when Horizon restarts, it will be using the latest codebase.
-
Purge Old Releases: This step is unrelated to Horizon and can proceed as usual.
By following this order, you ensure that Horizon is always running the latest code without any downtime. The key is to terminate Horizon just before activating the new release, so it restarts with the new code immediately after activation.
Here's a summary of the steps in code:
# Step 3: Terminate Horizon
php artisan horizon:terminate
# Step 4: Activate New Release
# (This is handled by Envoyer automatically)
This approach should help you maintain a smooth deployment process with zero downtime and ensure that your job processing is always up-to-date with the latest code.