1
0
Fork 0
mirror of synced 2024-05-20 12:42:39 +12:00

feat: publish delete events to resque

This commit is contained in:
Christy Jacob 2020-12-15 02:56:37 +05:30
parent 408ae68e7a
commit 4f997d3770
4 changed files with 580 additions and 148 deletions

View file

@ -2,18 +2,38 @@
global $cli;
require_once __DIR__.'/../init.php';
use Appwrite\Database\Database;
use Appwrite\Database\Document;
use Utopia\App;
use Utopia\CLI\Console;
$cli
->task('maintenance')
->desc('Schedules maintenance tasks and publishes them to resque')
->action(function () {
$interval = App::getEnv('_APP_MAINTENANCE_INTERVAL', '');
// Convert string to integer
$interval = App::getEnv('_APP_MAINTENANCE_INTERVAL', '') + 0;
//Convert Seconds to microseconds
$interval = $interval * 1000000;
Console::loop(function() {
$projects = $consoleDB->getCollection([
'filters' => [
'$collection='.Database::SYSTEM_COLLECTION_PROJECTS,
],
]);
var_dump("*************** MAINTENANCE WORKER *****************");
print_r($projects);
Resque::enqueue('v1-deletes', 'DeletesV1', [
'document' => new Document([
'$collection' => Database::SYSTEM_COLLECTION_EXECUTIONS,
'projectIds' => $this->projects
]),
]);
}, $interval);
for($i = 0; $i <= 10; ++$i){
Console::log('Starting the maintenance worker every '.$interval.' seconds');
sleep($interval);
}
});

View file

@ -39,6 +39,9 @@ class DeletesV1
case Database::SYSTEM_COLLECTION_FUNCTIONS:
$this->deleteFunction($document, $projectId);
break;
case Database::SYSTEM_COLLECTION_EXECUTIONS:
$this->deleteExecutionLogs($document);
break;
case Database::SYSTEM_COLLECTION_USERS:
$this->deleteUser($document, $projectId);
break;
@ -95,6 +98,26 @@ class DeletesV1
], $this->getProjectDB($projectId));
}
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(),
'$projectId='.$projectId
], $projectDB);
}
}
protected function deleteFunction(Document $document, $projectId)
{
$projectDB = $this->getProjectDB($projectId);

View file

@ -38,7 +38,7 @@
"utopia-php/abuse": "0.2.*",
"utopia-php/audit": "0.3.*",
"utopia-php/cache": "0.2.*",
"utopia-php/cli": "0.7.2",
"utopia-php/cli": "0.8.0",
"utopia-php/config": "0.2.*",
"utopia-php/locale": "0.3.*",
"utopia-php/registry": "0.2.*",

671
composer.lock generated

File diff suppressed because it is too large Load diff