From f10caa28ba9f387d1d4b3f8dfa37a1642c28d7f7 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Tue, 15 Dec 2020 19:08:41 +0530 Subject: [PATCH] feat: added maintenance worker for deleting execution logs --- Dockerfile | 2 +- app/tasks/maintenance.php | 29 +++++++++++++++++++++++++---- app/workers/deletes.php | 7 ++----- composer.lock | 14 +++++++------- 4 files changed, 35 insertions(+), 17 deletions(-) diff --git a/Dockerfile b/Dockerfile index eccefed79..cab447f8a 100755 --- a/Dockerfile +++ b/Dockerfile @@ -94,7 +94,7 @@ ENV _APP_SERVER=swoole \ _APP_FUNCTIONS_CONTAINERS=10 \ _APP_SETUP=self-hosted \ _APP_VERSION=$VERSION \ - _APP_MAINTENANCE_INTERVAL=10 + _APP_MAINTENANCE_INTERVAL=864000 #ENV _APP_SMTP_SECURE '' #ENV _APP_SMTP_USERNAME '' #ENV _APP_SMTP_PASSWORD '' diff --git a/app/tasks/maintenance.php b/app/tasks/maintenance.php index d3099f000..ac2501c0d 100644 --- a/app/tasks/maintenance.php +++ b/app/tasks/maintenance.php @@ -6,10 +6,23 @@ require_once __DIR__.'/../init.php'; use Appwrite\Database\Database; use Appwrite\Database\Document; +use Appwrite\Database\Adapter\MySQL as MySQLAdapter; +use Appwrite\Database\Adapter\Redis as RedisAdapter; +use Appwrite\Database\Validator\Authorization; use Utopia\App; use Utopia\CLI\Console; +use Utopia\Config\Config; +function getConsoleDB() { + global $register; + $consoleDB = new Database(); + $consoleDB->setAdapter(new RedisAdapter(new MySQLAdapter($register), $register)); + $consoleDB->setNamespace('app_console'); // Main DB + $consoleDB->setMocks(Config::getParam('collections', [])); + return $consoleDB; +} + $cli ->task('maintenance') ->desc('Schedules maintenance tasks and publishes them to resque') @@ -19,19 +32,27 @@ $cli //Convert Seconds to microseconds $interval = $interval * 1000000; - Console::loop(function() { + + $consoleDB = getConsoleDB(); + + Console::loop(function() use ($consoleDB){ + + Authorization::disable(); $projects = $consoleDB->getCollection([ 'filters' => [ '$collection='.Database::SYSTEM_COLLECTION_PROJECTS, ], ]); - var_dump("*************** MAINTENANCE WORKER *****************"); - print_r($projects); + Authorization::reset(); + + $projectIds = array_map (function ($project) { + return $project->getId(); + }, $projects); Resque::enqueue('v1-deletes', 'DeletesV1', [ 'document' => new Document([ '$collection' => Database::SYSTEM_COLLECTION_EXECUTIONS, - 'projectIds' => $this->projects + 'projectIds' => $projectIds ]), ]); }, $interval); diff --git a/app/workers/deletes.php b/app/workers/deletes.php index 8bc047e5d..18dfc4ab6 100644 --- a/app/workers/deletes.php +++ b/app/workers/deletes.php @@ -100,16 +100,13 @@ class DeletesV1 protected function deleteExecutionLogs(Document $document) { - var_dump("*********************DELETING EXECUTION LOGS *********************"); + $projectIds = $document->getAttribute('projectIds', []); - print_r($projectIds); foreach ($projectIds as $projectId) { if (!($projectDB = $this->getProjectDB($projectId))) { throw new Exception('Failed to get projectDB for project '.$projectId, 500); } - - var_dump("********************* DELETING FOR PROJECT *********************"); - var_dump($projectId); + // Delete Executions $this->deleteByGroup([ '$collection='.$document->getCollection(), diff --git a/composer.lock b/composer.lock index 022d6435a..ad4499c47 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "18cec0afcb76ef57fa38386fe04fd87b", + "content-hash": "58b7669908833b2a32d550d9e38f112f", "packages": [ { "name": "appwrite/php-clamav", @@ -1268,16 +1268,16 @@ }, { "name": "utopia-php/cli", - "version": "0.7.2", + "version": "0.8", "source": { "type": "git", "url": "https://github.com/utopia-php/cli.git", - "reference": "0b19cd33b86deb6aeb26bfdabc18bd2bdf5eba04" + "reference": "090c7ae22b53a175d962e8f9601d36350496153c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/cli/zipball/0b19cd33b86deb6aeb26bfdabc18bd2bdf5eba04", - "reference": "0b19cd33b86deb6aeb26bfdabc18bd2bdf5eba04", + "url": "https://api.github.com/repos/utopia-php/cli/zipball/090c7ae22b53a175d962e8f9601d36350496153c", + "reference": "090c7ae22b53a175d962e8f9601d36350496153c", "shasum": "" }, "require": { @@ -1315,9 +1315,9 @@ ], "support": { "issues": "https://github.com/utopia-php/cli/issues", - "source": "https://github.com/utopia-php/cli/tree/0.7.2" + "source": "https://github.com/utopia-php/cli/tree/0.8" }, - "time": "2020-10-23T13:34:41+00:00" + "time": "2020-12-14T06:31:42+00:00" }, { "name": "utopia-php/config",