Skip to content

Commit

Permalink
Add Horizon health check
Browse files Browse the repository at this point in the history
  • Loading branch information
kberzinch committed Jun 1, 2024
1 parent 637a49f commit 57c054d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
43 changes: 43 additions & 0 deletions app/HorizonHealthCheck.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace App;

use Laravel\Horizon\Contracts\MasterSupervisorRepository;
use UKFast\HealthCheck\HealthCheck;
use UKFast\HealthCheck\Status;

/**
* Verify Horizon is running.
*
* @author https://github.com/dominikager
*
* @source https://github.com/ans-group/laravel-health-check/issues/78#issue-1847102332
*/
class HorizonHealthCheck extends HealthCheck
{
/**
* The name for this health check.
*
* @var string
*/
protected $name = 'horizon';

public function __construct(private readonly MasterSupervisorRepository $supervisorRepository)
{
}

public function status(): Status
{
$masters = $this->supervisorRepository->all();

if (count($masters) === 0) {
return $this->problem('Horizon is inactive');
}

return collect($masters)->contains(
static fn (object $master): bool => $master->status === 'paused'
) ? $this->problem('Horizon is paused') : $this->okay();
}
}
1 change: 1 addition & 0 deletions config/healthcheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
\UKFast\HealthCheck\Checks\RedisHealthCheck::class,
\UKFast\HealthCheck\Checks\SchedulerHealthCheck::class,
\UKFast\HealthCheck\Checks\StorageHealthCheck::class,
\App\HorizonHealthCheck::class,
],

/**
Expand Down

0 comments on commit 57c054d

Please sign in to comment.