feat: added maintenance worker for deleting execution logs
This commit is contained in:
parent
4f997d3770
commit
f10caa28ba
|
@ -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 ''
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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(),
|
||||
|
|
14
composer.lock
generated
14
composer.lock
generated
|
@ -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",
|
||||
|
|
Loading…
Reference in a new issue