Add retry to first db connection and improve logging
This commit is contained in:
parent
53d3ae0419
commit
829240e38c
1 changed files with 11 additions and 1 deletions
12
app/http.php
12
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) {
|
||||
|
|
Loading…
Reference in a new issue