Skip to content
Snippets Groups Projects
Commit b94985f5 authored by Reiter, Christoph's avatar Reiter, Christoph :snake:
Browse files

Add some basic health checks

parent a79f1b8d
No related branches found
No related tags found
No related merge requests found
Pipeline #89360 passed
...@@ -3,6 +3,10 @@ services: ...@@ -3,6 +3,10 @@ services:
public: false public: false
autowire: true autowire: true
Dbp\Relay\CheckinBundle\Service\HealthCheck:
autowire: true
autoconfigure: true
Dbp\Relay\CheckinBundle\DataPersister\: Dbp\Relay\CheckinBundle\DataPersister\:
resource: '../../DataPersister' resource: '../../DataPersister'
autowire: true autowire: true
......
...@@ -141,6 +141,28 @@ class CheckinApi implements LoggerAwareInterface ...@@ -141,6 +141,28 @@ class CheckinApi implements LoggerAwareInterface
return new Client($client_options); return new Client($client_options);
} }
/**
* Check if CampusQR is reachable.
*/
public function checkConnection(): void
{
$client = $this->getClient();
$client->request('GET', $this->campusQRUrl);
}
/**
* Check if we can talk to the API.
*/
public function checkApi(): void
{
$client = $this->getClient();
$options = [
'headers' => ['X-Authorization' => $this->campusQRToken],
];
$url = $this->urls->getLocationListRequestUrl($this->campusQRUrl);
$client->request('GET', $url, $options);
}
private function getLocationClient(): Client private function getLocationClient(): Client
{ {
$stack = HandlerStack::create($this->clientHandler); $stack = HandlerStack::create($this->clientHandler);
......
<?php
declare(strict_types=1);
namespace Dbp\Relay\CheckinBundle\Service;
use Dbp\Relay\CoreBundle\HealthCheck\CheckInterface;
use Dbp\Relay\CoreBundle\HealthCheck\CheckOptions;
use Dbp\Relay\CoreBundle\HealthCheck\CheckResult;
class HealthCheck implements CheckInterface
{
private $api;
public function __construct(CheckinApi $api)
{
$this->api = $api;
}
public function getName(): string
{
return 'checkin';
}
public function checkConnection(): CheckResult
{
$result = new CheckResult('Check if CampusQR is reachable');
try {
$this->api->checkConnection();
} catch (\Throwable $e) {
$result->set(CheckResult::STATUS_FAILURE, $e->getMessage());
return $result;
}
$result->set(CheckResult::STATUS_SUCCESS);
return $result;
}
public function checkApi(): CheckResult
{
$result = new CheckResult('Check if we can use the CampusQR API');
try {
$this->api->checkApi();
} catch (\Throwable $e) {
$result->set(CheckResult::STATUS_FAILURE, $e->getMessage());
return $result;
}
$result->set(CheckResult::STATUS_SUCCESS);
return $result;
}
public function check(CheckOptions $options): array
{
return [
$this->checkConnection(),
$this->checkApi(),
];
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment