Follow these steps to use Laravel Horizon for Job Queuing in Statamic CMS when hosted with Laravel Forge. This guide assumes that Redis is already installed via Forge.
composer require laravel/horizon
and publish its assets php artisan horizon:install
HorizonServiceProvider.php
protected function gate()
{
Gate::define('viewHorizon', function ($user) {
return in_array($user->email, [
'user@host.com'
]);
});
}
config/horizon.php
'environments' => [
'production' => [
'supervisor-1' => [
'maxProcesses' => 10,
'balanceMaxShift' => 1,
'balanceCooldown' => 3,
'queue' => ['daarchitektur_production'],
],
],
'staging' => [
'supervisor-1' => [
'maxProcesses' => 10,
'balanceMaxShift' => 1,
'balanceCooldown' => 3,
'queue' => ['daarchitektur_staging'],
],
],
'local' => [
'supervisor-1' => [
'maxProcesses' => 3,
],
],
],
⚠️ Beware of maxProcesses
greater than 1
when using the Statamic Shopify addon, or make sure to use another a dedicated queue for that.
php artisan horizon
(This will make sure the horizon
command is always run and will restart it if it fails unexpectedly)The active daemon looks like this:
php artisan horizon:terminate
to the end of the deployment script. This will make sure the old Horizon workers are gracefully terminated on each deployment, and fresh Horizon workers will be started thanks to our daemon configuration.QUEUE_CONNECTION=redis
config/horizon.php
, e.g. REDIS_QUEUE=daarchitektur_staging
One way to test if everything works is by enabling Git integration with dispatch delay.
STATAMIC_GIT_ENABLED=true
STATAMIC_GIT_PUSH=true
STATAMIC_GIT_DISPATCH_DELAY=10
STATAMIC_GIT_AUTOMATIC=true
Clear the config cache, log into Statamic CP, make some content changes and open the Horizon Dashboard (you’ll have access as soon as you’re logged in with a user who has been added to HorizonServiceProvider.php
). There’s even a convenient link in the Statamic panel:
You should see a pending task being spawned as soon as you save content changes. After the amount of minutes you’ve set for STATAMIC_GIT_DISPATCH_DELAY
, Pending Jobs should be processed and move over to Completed Jobs: