Update the healthcheck

This commit is contained in:
Dave Smith-Hayes 2024-06-26 22:15:43 -04:00
parent 9ab1482acf
commit c8b9abf559

View File

@ -3,27 +3,23 @@
namespace Slovocast\Controller; namespace Slovocast\Controller;
use Slovocast\Controller\Controller; use Slovocast\Controller\Controller;
use Slovocast\Infrastructure\DatabaseConnectionInterface; use React\Mysql\MysqlClient;
use function React\Async\await;
use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ResponseInterface as Response;
class HealthCheck extends Controller class HealthCheck extends Controller
{ {
public function __construct( public function __construct(
protected DatabaseConnectionInterface $connection protected MysqlClient $db
) { } ) { }
public function handle(): Response public function handle(): Response
{ {
/** $results = await($this->db->query("SELECT 1"));
* Check if the Database connections are active
* @var PdoDatabaseConnection $this->connection
*/
$stmt = $this->connection->query("SELECT 1");
$dbResult = $stmt->fetch();
return $this->json([ return $this->json([
'http' => true, 'http' => true,
'database' => (bool) $dbResult[0] 'database' => (bool) count($results->resultRows);
]); ]);
} }
} }