Skip to content

Latest commit

 

History

History
44 lines (35 loc) · 1003 Bytes

adding-a-healthcheck.md

File metadata and controls

44 lines (35 loc) · 1003 Bytes

Adding a healthcheck

namespace App\Health;

use Instrumentation\Health\HealthcheckInterface;
use Symfony\Component\HttpFoundation\RequestStack;

class DummyHealthcheck implements HealthcheckInterface
{
    public function __construct(private RequestStack $requestStack)
    {
    }

    public function getName(): string
    {
        return 'Dummy';
    }

    public function getDescription(): ?string
    {
        return 'Dummy healthcheck that retrieves the status from incoming "X-Dummy-Status" request header';
    }

    public function getStatus(): string
    {
        if ($header = $this->requestStack->getMainRequest()->headers->get('X-Dummy-Status', null)) {
            return $header;
        }

        return HealthcheckInterface::HEALTHY;
    }

    public function getStatusMessage(): ?string
    {
        return sprintf('I am in %s state because you told me so ;)', $this->getStatus());
    }

    public function isCritical(): bool
    {
        return true;
    }
}