From adf3f74ef2f1baacf92839d9667d3021b7206a98 Mon Sep 17 00:00:00 2001 From: Damodar Lohani Date: Sun, 23 Oct 2022 08:19:10 +0000 Subject: [PATCH] refill pools on exception --- app/cli.php | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/app/cli.php b/app/cli.php index 23cea75306..94830490af 100644 --- a/app/cli.php +++ b/app/cli.php @@ -47,11 +47,20 @@ function getConsoleDB(): Database $pools = $register->get('pools'); /** @var \Utopia\Pools\Group $pools */ - $dbAdapter = $pools - ->get('console') - ->pop() - ->getResource() - ; + try { + $dbAdapter = $pools + ->get('console') + ->pop() + ->getResource() + ; + } catch (Throwable $error) { + $pools->fill(); + $dbAdapter = $pools + ->get('console') + ->pop() + ->getResource() + ; + } $database = new Database($dbAdapter, getCache()); @@ -71,11 +80,20 @@ function getProjectDB(Document $project): Database return getConsoleDB(); } - $dbAdapter = $pools - ->get($project->getAttribute('database')) - ->pop() - ->getResource() - ; + try { + $dbAdapter = $pools + ->get($project->getAttribute('database')) + ->pop() + ->getResource() + ; + } catch (Throwable $error) { + $pools->fill(); + $dbAdapter = $pools + ->get($project->getAttribute('database')) + ->pop() + ->getResource() + ; + } $database = new Database($dbAdapter, getCache()); $database->setNamespace('_' . $project->getInternalId());