Merge pull request #2225 from PineappleIOnic/health-improve-db-test
Improve health check for Database
This commit is contained in:
commit
3741786e07
1 changed files with 20 additions and 4 deletions
|
@ -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')
|
||||
|
|
Loading…
Reference in a new issue