Wire HealthCheckService in container

This commit is contained in:
Cedric Ziel
2020-04-16 10:07:07 +02:00
committed by Cedric Ziel
parent 09b571c87e
commit 8ea413da09
2 changed files with 12 additions and 2 deletions

View File

@@ -8,6 +8,7 @@ use Instana\RobotShop\Ratings\Controller\HealthController;
use Instana\RobotShop\Ratings\Controller\RatingsApiController;
use Instana\RobotShop\Ratings\Integration\InstanaHeadersLoggingProcessor;
use Instana\RobotShop\Ratings\Service\CatalogueService;
use Instana\RobotShop\Ratings\Service\HealthCheckService;
use Instana\RobotShop\Ratings\Service\RatingsService;
use Monolog\Formatter\LineFormatter;
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
@@ -96,6 +97,11 @@ class Kernel extends BaseKernel implements EventSubscriberInterface
->addMethodCall('setLogger', [new Reference('logger')])
->setAutowired(true);
$c->register(HealthCheckService::class)
->addArgument(new Reference('database.connection'))
->addMethodCall('setLogger', [new Reference('logger')])
->setAutowired(true);
$c->register('database.connection', \PDO::class)
->setFactory([new Reference(Database::class), 'getConnection']);

View File

@@ -5,9 +5,13 @@ declare(strict_types=1);
namespace Instana\RobotShop\Ratings\Service;
use PDO;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
class HealthCheckService
class HealthCheckService implements LoggerAwareInterface
{
use LoggerAwareTrait;
/**
* @var PDO
*/
@@ -18,7 +22,7 @@ class HealthCheckService
$this->pdo = $pdo;
}
public function checkConnectivity()
public function checkConnectivity(): bool
{
return $this->pdo->prepare('SELECT 1 + 1 FROM DUAL;')->execute();
}