Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Horizon Healthcheck #78

Open
dominikager opened this issue Aug 11, 2023 · 0 comments
Open

Horizon Healthcheck #78

dominikager opened this issue Aug 11, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@dominikager
Copy link

What is the feature?

With the following code, you can easily check if Laravel Horizon is active. Just create a custom Healthcheck.

<?php

namespace App\HealthChecks;

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

class HorizonHealthCheck extends HealthCheck
{
    protected $name = 'horizon';

    private MasterSupervisorRepository $masterSupervisorRepository;

    /**
     * @param MasterSupervisorRepository $masterSupervisorRepository
     */
    public function __construct(MasterSupervisorRepository $masterSupervisorRepository)
    {
        $this->masterSupervisorRepository = $masterSupervisorRepository;
    }

    /**
     * @return Status
     */
    public function status(): Status
    {
        if (! $masters = $this->masterSupervisorRepository->all()) {
            return $this->problem('Horizon is inactive.');
        }

        return collect($masters)->contains(function ($master) {
            return $master->status === 'paused';
        }) ? $this->problem('Horizon is paused.') : $this->okay();
    }
}

@dominikager dominikager added the enhancement New feature or request label Aug 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

No branches or pull requests

1 participant