From 5dd31bcdfbe019e27b7d5b80ffcb980e1809ace4 Mon Sep 17 00:00:00 2001 From: Matej Baco Date: Wed, 16 Nov 2022 20:53:59 +0100 Subject: [PATCH] Fix init startup --- app/cli.php | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/app/cli.php b/app/cli.php index 1d0a41128b..9dec6118f6 100644 --- a/app/cli.php +++ b/app/cli.php @@ -179,25 +179,29 @@ $cli do { $attempts++; - // Prepare database connection - $dbAdapter = $pools - ->get('console') - ->pop() - ->getResource(); + try { + // Prepare database connection + $dbAdapter = $pools + ->get('console') + ->pop() + ->getResource(); - $dbForConsole = new Database($dbAdapter, $cache); - $dbForConsole->setNamespace('console'); + $dbForConsole = new Database($dbAdapter, $cache); + $dbForConsole->setNamespace('console'); - // Ensure tables exist - $collections = Config::getParam('collections', []); - $last = \array_key_last($collections); + // Ensure tables exist + $collections = Config::getParam('collections', []); + $last = \array_key_last($collections); + + if (!($dbForConsole->exists($dbForConsole->getDefaultDatabase(), $last))) { + throw new Exception('Tables not ready yet.'); + } - if ($dbForConsole->exists($dbForConsole->getDefaultDatabase(), $last)) { $ready = true; - break; + } catch (\Exception $err) { + Console::warning($err->getMessage()); + sleep($sleep); } - - sleep($sleep); } while ($attempts < $maxAttempts); if (!$ready) {