Skip to content

Commit 0020921

Browse files
committed
Improve queue stats output
1 parent 926236a commit 0020921

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

app/Health/QueueLengthCheck.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
}

app/Providers/HealthCheckProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Providers;
44

5+
use App\Health\QueueLengthCheck;
56
use Illuminate\Support\ServiceProvider;
67
use Spatie\CpuLoadHealthCheck\CpuLoadCheck;
78
use 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
]);

routes/console.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
Schedule::command(CleanupSitesList::class)->everySixHours();
99
Schedule::command(PruneFailedJobsCommand::class)->daily();
1010
Schedule::command(QueueHealthChecks::class)->everyFifteenMinutes();
11+
Schedule::command('horizon:snapshot')->everyFiveMinutes();

0 commit comments

Comments
 (0)