1
0
Fork 0
mirror of synced 2024-06-18 18:54:55 +12:00

Add retry to first db connection and improve logging

This commit is contained in:
kodumbeats 2021-06-16 16:32:10 -04:00
parent 53d3ae0419
commit 829240e38c

View file

@ -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) {