File tree Expand file tree Collapse file tree 3 files changed +33
-0
lines changed
Expand file tree Collapse file tree 3 files changed +33
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace App \Health ;
4+
5+ use Laravel \Horizon \Contracts \JobRepository ;
6+ use Spatie \Health \Checks \Check ;
7+ use Spatie \Health \Checks \Result ;
8+ class QueueLengthCheck extends Check
9+ {
10+ public function run (): Result
11+ {
12+ /** @var JobRepository $jobs */
13+ $ jobs = app (JobRepository::class);
14+
15+ $ result = Result::make ()
16+ ->appendMeta ([
17+ 'pending ' => $ jobs ->countPending (),
18+ 'failed ' => $ jobs ->countFailed (),
19+ 'completed ' => $ jobs ->countCompleted ()
20+ ]);
21+
22+ if ($ jobs ->countPending () > 50000 ) {
23+ return $ result
24+ ->failed ('Job queue larger than 50.000 items ' )
25+ ->shortSummary ('Excessive queue length ' );
26+ }
27+
28+ return $ result ->ok ();
29+ }
30+ }
Original file line number Diff line number Diff line change 22
33namespace App \Providers ;
44
5+ use App \Health \QueueLengthCheck ;
56use Illuminate \Support \ServiceProvider ;
67use Spatie \CpuLoadHealthCheck \CpuLoadCheck ;
78use Spatie \Health \Checks \Checks \DatabaseCheck ;
@@ -29,6 +30,7 @@ public function boot(): void
2930 UsedDiskSpaceCheck::new (),
3031 DatabaseCheck::new (),
3132 HorizonCheck::new (),
33+ QueueLengthCheck::new (),
3234 RedisCheck::new (),
3335 CpuLoadCheck::new ()
3436 ]);
Original file line number Diff line number Diff line change 88Schedule::command (CleanupSitesList::class)->everySixHours ();
99Schedule::command (PruneFailedJobsCommand::class)->daily ();
1010Schedule::command (QueueHealthChecks::class)->everyFifteenMinutes ();
11+ Schedule::command ('horizon:snapshot ' )->everyFiveMinutes ();
You can’t perform that action at this time.
0 commit comments