From 829240e38cf0f3616e888819c2068f5194556557 Mon Sep 17 00:00:00 2001 From: kodumbeats Date: Wed, 16 Jun 2021 16:32:10 -0400 Subject: [PATCH] Add retry to first db connection and improve logging --- app/http.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/http.php b/app/http.php index 0e67e07c3..d0d8447e2 100644 --- a/app/http.php +++ b/app/http.php @@ -59,7 +59,15 @@ include __DIR__ . '/controllers/general.php'; $http->on('start', function (Server $http) use ($payloadSize, $register) { $app = new App('UTC'); - $dbForConsole = $app->getResource('dbForConsole'); /** @var Utopia\Database\Database $dbForConsole */ + + // Only retry connection once before throwing exception + try { + $dbForConsole = $app->getResource('dbForConsole'); /** @var Utopia\Database\Database $dbForConsole */ + } catch (\Exception $exception) { + Console::warning('[Setup] - Database not ready. Waiting for five seconds...'); + sleep(5); + $dbForConsole = $app->getResource('dbForConsole'); /** @var Utopia\Database\Database $dbForConsole */ + } if(!$dbForConsole->exists()) { Console::success('[Setup] - Server database init started...'); @@ -77,6 +85,8 @@ $http->on('start', function (Server $http) use ($payloadSize, $register) { $adapter->setup(); foreach ($collections as $key => $collection) { + Console::success('[Setup] - Creating collection: ' . $collection['$id'] . '...'); + $dbForConsole->createCollection($key); foreach ($collection['attributes'] as $i => $attribute) {