Last active
December 30, 2025 08:35
-
-
Save ankurk91/4cddb9949a653e713bad8a0e75144678 to your computer and use it in GitHub Desktop.
How to get notified when Laravel Horizon stops running
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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(); | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Reserved