Skip to content

Instantly share code, notes, and snippets.

@ankurk91
Last active December 30, 2025 08:35
Show Gist options
  • Select an option

  • Save ankurk91/4cddb9949a653e713bad8a0e75144678 to your computer and use it in GitHub Desktop.

Select an option

Save ankurk91/4cddb9949a653e713bad8a0e75144678 to your computer and use it in GitHub Desktop.
How to get notified when Laravel Horizon stops running
<?php
namespace App\Console;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Laravel\Horizon\Contracts\MasterSupervisorRepository;
// https://smknstd.medium.com/how-to-get-notified-when-laravel-horizon-stops-running-a17206e0adb6
class Kernel extends ConsoleKernel
{
protected function isHorizonActive() : bool
{
if (! $masters = app(MasterSupervisorRepository::class)->all()) {
return false;
}
return collect($masters)->some(function ($master) {
return $master->status !== 'paused';
});
}
protected function schedule(Schedule $schedule)
{
$schedule
->call(function () {
if (!$this->isHorizonActive()) {
// notify your team, dont use any queued job here
}
})
->everyFiveMinutes();
}
}
@ankurk91
Copy link
Author

ankurk91 commented Dec 10, 2022

Reserved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment