From f988a89cf3d7a1b256015b7221f7635a3a0552d2 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Fri, 15 Oct 2021 10:05:21 +0100 Subject: [PATCH 1/4] Update health.php --- app/controllers/api/health.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/health.php b/app/controllers/api/health.php index cbccb8f59c..bd7721d463 100644 --- a/app/controllers/api/health.php +++ b/app/controllers/api/health.php @@ -5,6 +5,7 @@ use Utopia\Exception; use Utopia\Storage\Device\Local; use Utopia\Storage\Storage; use Appwrite\ClamAV\Network; +use Appwrite\Database\Database; use Appwrite\Event\Event; App::get('/v1/health') @@ -46,9 +47,18 @@ App::get('/v1/health/db') ->action(function ($response, $utopia) { /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\App $utopia */ - $utopia->getResource('db'); + $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(); + + return $response->json(['status' => 'OK']); }); App::get('/v1/health/cache') From 7540dafa9bdb7de684427b97aaa729b897b83234 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Fri, 15 Oct 2021 10:40:25 +0100 Subject: [PATCH 2/4] Update health.php --- app/controllers/api/health.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/app/controllers/api/health.php b/app/controllers/api/health.php index bd7721d463..9a0edd6bc2 100644 --- a/app/controllers/api/health.php +++ b/app/controllers/api/health.php @@ -5,7 +5,6 @@ use Utopia\Exception; use Utopia\Storage\Device\Local; use Utopia\Storage\Storage; use Appwrite\ClamAV\Network; -use Appwrite\Database\Database; use Appwrite\Event\Event; App::get('/v1/health') @@ -50,9 +49,7 @@ App::get('/v1/health/db') $db = $utopia->getResource('db'); /* @var $db PDO */ // Run a small test to check the connection - $statement = $db->prepare(" - SELECT 1;" - ); + $statement = $db->prepare("SELECT 1;"); $statement->closeCursor(); From aca61d19027692a3d70ada8df2851276ed0d1b5b Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Mon, 18 Oct 2021 16:08:50 +0100 Subject: [PATCH 3/4] Update Cache Test --- app/controllers/api/health.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/health.php b/app/controllers/api/health.php index 9a0edd6bc2..96b5f82b65 100644 --- a/app/controllers/api/health.php +++ b/app/controllers/api/health.php @@ -71,9 +71,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') From 91827930c004bd47bbdbe960e487115396605fa9 Mon Sep 17 00:00:00 2001 From: Bradley Schofield Date: Wed, 27 Oct 2021 10:21:16 +0100 Subject: [PATCH 4/4] Improve exception --- app/controllers/api/health.php | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/app/controllers/api/health.php b/app/controllers/api/health.php index 96b5f82b65..7b215f74e9 100644 --- a/app/controllers/api/health.php +++ b/app/controllers/api/health.php @@ -46,14 +46,18 @@ App::get('/v1/health/db') ->action(function ($response, $utopia) { /** @var Appwrite\Utopia\Response $response */ /** @var Utopia\App $utopia */ - $db = $utopia->getResource('db'); /* @var $db PDO */ + try { + $db = $utopia->getResource('db'); /* @var $db PDO */ - // Run a small test to check the connection - $statement = $db->prepare("SELECT 1;"); - - $statement->closeCursor(); - - $statement->execute(); + // 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']); });