Merge pull request #4720 from appwrite/fix-volume-sync
fix: volume sync
This commit is contained in:
commit
7694e19322
3 changed files with 49 additions and 55 deletions
83
app/cli.php
83
app/cli.php
|
@ -43,17 +43,44 @@ CLI::setResource('pools', function (Registry $register) {
|
||||||
}, ['register']);
|
}, ['register']);
|
||||||
|
|
||||||
CLI::setResource('dbForConsole', function ($pools, $cache) {
|
CLI::setResource('dbForConsole', function ($pools, $cache) {
|
||||||
|
$sleep = 3;
|
||||||
|
$maxAttempts = 5;
|
||||||
|
$attempts = 0;
|
||||||
|
$ready = false;
|
||||||
|
|
||||||
|
do {
|
||||||
|
$attempts++;
|
||||||
|
try {
|
||||||
|
// Prepare database connection
|
||||||
$dbAdapter = $pools
|
$dbAdapter = $pools
|
||||||
->get('console')
|
->get('console')
|
||||||
->pop()
|
->pop()
|
||||||
->getResource()
|
->getResource();
|
||||||
;
|
|
||||||
|
|
||||||
$database = new Database($dbAdapter, $cache);
|
$dbForConsole = new Database($dbAdapter, $cache);
|
||||||
|
$dbForConsole->setNamespace('console');
|
||||||
|
|
||||||
$database->setNamespace('console');
|
// Ensure tables exist
|
||||||
|
$collections = Config::getParam('collections', []);
|
||||||
|
$last = \array_key_last($collections);
|
||||||
|
|
||||||
return $database;
|
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']);
|
}, ['pools', 'cache']);
|
||||||
|
|
||||||
CLI::setResource('getProjectDB', function (Group $pools, Database $dbForConsole, $cache) {
|
CLI::setResource('getProjectDB', function (Group $pools, Database $dbForConsole, $cache) {
|
||||||
|
@ -165,50 +192,4 @@ $cli
|
||||||
Console::error($error->getMessage());
|
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();
|
$cli->run();
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 6aa50b8b96b7941a710fe097f3f4d3a74f1eb823
|
Subproject commit 4e2cecefb571104f0dbbe5a578729f0e17a10242
|
|
@ -770,6 +770,19 @@ services:
|
||||||
networks:
|
networks:
|
||||||
- appwrite
|
- 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:
|
# redis-commander:
|
||||||
# image: rediscommander/redis-commander:latest
|
# image: rediscommander/redis-commander:latest
|
||||||
# networks:
|
# networks:
|
||||||
|
|
Loading…
Reference in a new issue