1
0
Fork 0
mirror of synced 2024-06-03 03:14:50 +12:00

feat: added maintenance worker for deleting execution logs

This commit is contained in:
Christy Jacob 2020-12-15 19:08:41 +05:30
parent 4f997d3770
commit f10caa28ba
4 changed files with 35 additions and 17 deletions

View file

@ -94,7 +94,7 @@ ENV _APP_SERVER=swoole \
_APP_FUNCTIONS_CONTAINERS=10 \ _APP_FUNCTIONS_CONTAINERS=10 \
_APP_SETUP=self-hosted \ _APP_SETUP=self-hosted \
_APP_VERSION=$VERSION \ _APP_VERSION=$VERSION \
_APP_MAINTENANCE_INTERVAL=10 _APP_MAINTENANCE_INTERVAL=864000
#ENV _APP_SMTP_SECURE '' #ENV _APP_SMTP_SECURE ''
#ENV _APP_SMTP_USERNAME '' #ENV _APP_SMTP_USERNAME ''
#ENV _APP_SMTP_PASSWORD '' #ENV _APP_SMTP_PASSWORD ''

View file

@ -6,10 +6,23 @@ require_once __DIR__.'/../init.php';
use Appwrite\Database\Database; use Appwrite\Database\Database;
use Appwrite\Database\Document; 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\App;
use Utopia\CLI\Console; 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 $cli
->task('maintenance') ->task('maintenance')
->desc('Schedules maintenance tasks and publishes them to resque') ->desc('Schedules maintenance tasks and publishes them to resque')
@ -19,19 +32,27 @@ $cli
//Convert Seconds to microseconds //Convert Seconds to microseconds
$interval = $interval * 1000000; $interval = $interval * 1000000;
Console::loop(function() {
$consoleDB = getConsoleDB();
Console::loop(function() use ($consoleDB){
Authorization::disable();
$projects = $consoleDB->getCollection([ $projects = $consoleDB->getCollection([
'filters' => [ 'filters' => [
'$collection='.Database::SYSTEM_COLLECTION_PROJECTS, '$collection='.Database::SYSTEM_COLLECTION_PROJECTS,
], ],
]); ]);
var_dump("*************** MAINTENANCE WORKER *****************"); Authorization::reset();
print_r($projects);
$projectIds = array_map (function ($project) {
return $project->getId();
}, $projects);
Resque::enqueue('v1-deletes', 'DeletesV1', [ Resque::enqueue('v1-deletes', 'DeletesV1', [
'document' => new Document([ 'document' => new Document([
'$collection' => Database::SYSTEM_COLLECTION_EXECUTIONS, '$collection' => Database::SYSTEM_COLLECTION_EXECUTIONS,
'projectIds' => $this->projects 'projectIds' => $projectIds
]), ]),
]); ]);
}, $interval); }, $interval);

View file

@ -100,16 +100,13 @@ class DeletesV1
protected function deleteExecutionLogs(Document $document) protected function deleteExecutionLogs(Document $document)
{ {
var_dump("*********************DELETING EXECUTION LOGS *********************");
$projectIds = $document->getAttribute('projectIds', []); $projectIds = $document->getAttribute('projectIds', []);
print_r($projectIds);
foreach ($projectIds as $projectId) { foreach ($projectIds as $projectId) {
if (!($projectDB = $this->getProjectDB($projectId))) { if (!($projectDB = $this->getProjectDB($projectId))) {
throw new Exception('Failed to get projectDB for project '.$projectId, 500); throw new Exception('Failed to get projectDB for project '.$projectId, 500);
} }
var_dump("********************* DELETING FOR PROJECT *********************");
var_dump($projectId);
// Delete Executions // Delete Executions
$this->deleteByGroup([ $this->deleteByGroup([
'$collection='.$document->getCollection(), '$collection='.$document->getCollection(),

14
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "18cec0afcb76ef57fa38386fe04fd87b", "content-hash": "58b7669908833b2a32d550d9e38f112f",
"packages": [ "packages": [
{ {
"name": "appwrite/php-clamav", "name": "appwrite/php-clamav",
@ -1268,16 +1268,16 @@
}, },
{ {
"name": "utopia-php/cli", "name": "utopia-php/cli",
"version": "0.7.2", "version": "0.8",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/utopia-php/cli.git", "url": "https://github.com/utopia-php/cli.git",
"reference": "0b19cd33b86deb6aeb26bfdabc18bd2bdf5eba04" "reference": "090c7ae22b53a175d962e8f9601d36350496153c"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/utopia-php/cli/zipball/0b19cd33b86deb6aeb26bfdabc18bd2bdf5eba04", "url": "https://api.github.com/repos/utopia-php/cli/zipball/090c7ae22b53a175d962e8f9601d36350496153c",
"reference": "0b19cd33b86deb6aeb26bfdabc18bd2bdf5eba04", "reference": "090c7ae22b53a175d962e8f9601d36350496153c",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1315,9 +1315,9 @@
], ],
"support": { "support": {
"issues": "https://github.com/utopia-php/cli/issues", "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", "name": "utopia-php/config",