1
0
Fork 0
mirror of synced 2024-06-29 11:40:45 +12:00

Merge pull request #2225 from PineappleIOnic/health-improve-db-test

Improve health check for Database
This commit is contained in:
Torsten Dittmann 2021-11-08 10:42:55 +01:00 committed by GitHub
commit 3741786e07
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -46,9 +46,20 @@ App::get('/v1/health/db')
->action(function ($response, $utopia) {
/** @var Appwrite\Utopia\Response $response */
/** @var Utopia\App $utopia */
$utopia->getResource('db');
try {
$db = $utopia->getResource('db'); /* @var $db PDO */
$response->json(['status' => 'OK']);
// Run a small test to check the connection
$statement = $db->prepare("SELECT 1;");
$statement->closeCursor();
$statement->execute();
} catch (Exception $_e) {
throw new Exception('Database is not available', 500);
}
return $response->json(['status' => 'OK']);
});
App::get('/v1/health/cache')
@ -64,9 +75,14 @@ App::get('/v1/health/cache')
->action(function ($response, $utopia) {
/** @var Appwrite\Utopia\Response $response */
/** @var Utopia\App $utopia */
$utopia->getResource('cache');
/** @var Redis */
$redis = $utopia->getResource('cache');
$response->json(['status' => 'OK']);
if ($redis->ping(true)) {
return $response->json(['status' => 'OK']);
} else {
throw new Exception('Cache is not available', 500);
}
});
App::get('/v1/health/time')