From 2cfb67734fcd339cfa815ac4b73cfe72978244e3 Mon Sep 17 00:00:00 2001 From: Christoph Reiter <reiter.christoph@gmail.com> Date: Tue, 17 May 2022 10:26:52 +0200 Subject: [PATCH] Add a health check example --- src/HealthCheck/HealthCheck.php | 32 ++++++++++++++++++++++++++++++ src/Resources/config/services.yaml | 4 ++++ 2 files changed, 36 insertions(+) create mode 100644 src/HealthCheck/HealthCheck.php diff --git a/src/HealthCheck/HealthCheck.php b/src/HealthCheck/HealthCheck.php new file mode 100644 index 0000000..f45b9e0 --- /dev/null +++ b/src/HealthCheck/HealthCheck.php @@ -0,0 +1,32 @@ +<?php + +declare(strict_types=1); + +namespace Dbp\Relay\ExampleBundle\HealthCheck; + +use Dbp\Relay\CoreBundle\HealthCheck\CheckInterface; +use Dbp\Relay\CoreBundle\HealthCheck\CheckOptions; +use Dbp\Relay\CoreBundle\HealthCheck\CheckResult; + +class HealthCheck implements CheckInterface +{ + public function getName(): string + { + return 'example'; + } + + public function check(CheckOptions $options): array + { + $ok = new CheckResult('Check that everything is OK'); + $ok->set(CheckResult::STATUS_SUCCESS, 'everything OK'); + + $failed = new CheckResult('Check something different'); + try { + throw new \RuntimeException('oh no'); + } catch (\Throwable $e) { + $failed->set(CheckResult::STATUS_FAILURE, $e->getMessage(), ['exception' => $e]); + } + + return [$ok, $failed]; + } +} diff --git a/src/Resources/config/services.yaml b/src/Resources/config/services.yaml index 3ed8519..0632d74 100644 --- a/src/Resources/config/services.yaml +++ b/src/Resources/config/services.yaml @@ -22,6 +22,10 @@ services: autowire: true autoconfigure: true + Dbp\Relay\ExampleBundle\HealthCheck\HealthCheck: + autowire: true + autoconfigure: true + Dbp\Relay\ExampleBundle\Service\MyCustomService: autowire: true autoconfigure: true -- GitLab