From 9698dc2115b8904cf08553c726e12d04d485c5c5 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Fri, 18 Nov 2022 22:18:27 +0530 Subject: [PATCH] fix: volume sync --- app/cli.php | 89 ++++++++++++++++++---------------------------- app/console | 2 +- docker-compose.yml | 13 +++++++ 3 files changed, 49 insertions(+), 55 deletions(-) diff --git a/app/cli.php b/app/cli.php index 9857261b4..bfe7bfcef 100644 --- a/app/cli.php +++ b/app/cli.php @@ -43,17 +43,44 @@ CLI::setResource('pools', function (Registry $register) { }, ['register']); CLI::setResource('dbForConsole', function ($pools, $cache) { - $dbAdapter = $pools - ->get('console') - ->pop() - ->getResource() - ; + $sleep = 3; + $maxAttempts = 5; + $attempts = 0; + $ready = false; - $database = new Database($dbAdapter, $cache); + do { + $attempts++; + try { + // Prepare database connection + $dbAdapter = $pools + ->get('console') + ->pop() + ->getResource(); - $database->setNamespace('console'); + $dbForConsole = new Database($dbAdapter, $cache); + $dbForConsole->setNamespace('console'); - return $database; + // Ensure tables exist + $collections = Config::getParam('collections', []); + $last = \array_key_last($collections); + + if (!($dbForConsole->exists($dbForConsole->getDefaultDatabase(), $last))) { /** TODO cache ready variable using registry */ + throw new Exception('Tables not ready yet.'); + } + + $ready = true; + } catch (\Exception $err) { + Console::warning($err->getMessage()); + $pools->get('console')->reclaim(); + sleep($sleep); + } + } while ($attempts < $maxAttempts); + + if (!$ready) { + throw new Exception("Console is not ready yet. Please try again later."); + } + + return $dbForConsole; }, ['pools', 'cache']); CLI::setResource('getProjectDB', function (Group $pools, Database $dbForConsole, $cache) { @@ -165,50 +192,4 @@ $cli Console::error($error->getMessage()); }); -$cli - ->init() - ->inject('pools') - ->inject('cache') - ->action(function (Group $pools, Cache $cache) { - $maxAttempts = 5; - $sleep = 3; - - $attempts = 0; - $ready = false; - - do { - $attempts++; - - try { - $pools->get('console')->reclaim(); - - // Prepare database connection - $dbAdapter = $pools - ->get('console') - ->pop() - ->getResource(); - - $dbForConsole = new Database($dbAdapter, $cache); - $dbForConsole->setNamespace('console'); - - // 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.'); - } - - $ready = true; - } catch (\Exception $err) { - Console::warning($err->getMessage()); - sleep($sleep); - } - } while ($attempts < $maxAttempts); - - if (!$ready) { - throw new Exception("Console is not ready yet. Please try again later."); - } - }); - $cli->run(); diff --git a/app/console b/app/console index 6aa50b8b9..4e2cecefb 160000 --- a/app/console +++ b/app/console @@ -1 +1 @@ -Subproject commit 6aa50b8b96b7941a710fe097f3f4d3a74f1eb823 +Subproject commit 4e2cecefb571104f0dbbe5a578729f0e17a10242 diff --git a/docker-compose.yml b/docker-compose.yml index 4ca8876f9..cb18dff4e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -769,6 +769,19 @@ services: - 9506:8080 networks: - appwrite + + # appwrite-volume-sync: + # entrypoint: volume-sync + # <<: *x-logging + # container_name: appwrite-volume-sync + # image: appwrite-dev + # command: + # - --source=/data/src/ --destination=/data/dest/ --interval=10 + # networks: + # - appwrite + # # volumes: # Mount the rsync source and destination directories + # # - /nfs/config:/data/src + # # - /storage/config:/data/dest # redis-commander: # image: rediscommander/redis-commander:latest