2025-08-06 09:34:15 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
*/
|
|
|
|
|
namespace OC\Core\Command\TaskProcessing;
|
|
|
|
|
|
|
|
|
|
use OC\Core\Command\Base;
|
|
|
|
|
use OC\TaskProcessing\Manager;
|
|
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
|
|
|
|
|
class Cleanup extends Base {
|
|
|
|
|
public function __construct(
|
|
|
|
|
protected Manager $taskProcessingManager,
|
|
|
|
|
) {
|
|
|
|
|
parent::__construct();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function configure() {
|
|
|
|
|
$this
|
|
|
|
|
->setName('taskprocessing:task:cleanup')
|
|
|
|
|
->setDescription('cleanup old tasks')
|
|
|
|
|
->addArgument(
|
|
|
|
|
'maxAgeSeconds',
|
|
|
|
|
InputArgument::OPTIONAL,
|
|
|
|
|
// default is not defined as an argument default value because we want to show a nice "4 months" value
|
|
|
|
|
'delete tasks that are older than this number of seconds, defaults to ' . Manager::MAX_TASK_AGE_SECONDS . ' (4 months)',
|
|
|
|
|
);
|
|
|
|
|
parent::configure();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int {
|
|
|
|
|
$maxAgeSeconds = $input->getArgument('maxAgeSeconds') ?? Manager::MAX_TASK_AGE_SECONDS;
|
2025-08-06 10:00:44 -04:00
|
|
|
$output->writeln('<comment>Cleanup up tasks older than '. $maxAgeSeconds . ' seconds and the related output files</comment>');
|
2025-08-06 09:34:15 -04:00
|
|
|
$cleanupResult = $this->taskProcessingManager->cleanupOldTasks($maxAgeSeconds);
|
|
|
|
|
foreach ($cleanupResult as $entry) {
|
|
|
|
|
if (isset($entry['task_id'], $entry['file_id'], $entry['file_name'])) {
|
2025-08-06 10:00:44 -04:00
|
|
|
$output->writeln("<info>\t - " . 'Deleted appData/core/TaskProcessing/' . $entry['file_name'] . ' (fileId: ' . $entry['file_id'] . ', taskId: ' . $entry['task_id'] . ')</info>');
|
2025-08-06 09:34:15 -04:00
|
|
|
} elseif (isset($entry['directory_name'])) {
|
2025-08-06 10:00:44 -04:00
|
|
|
$output->writeln("<info>\t - " . 'Deleted appData/core/'. $entry['directory_name'] . '/' . $entry['file_name'] . '</info>');
|
2025-08-06 09:34:15 -04:00
|
|
|
} elseif (isset($entry['deleted_task_count'])) {
|
2025-08-06 10:00:44 -04:00
|
|
|
$output->writeln("<comment>\t - " . 'Deleted '. $entry['deleted_task_count'] . ' tasks from the database</comment>');
|
|
|
|
|
} elseif (isset($entry['deleted_task_id_list'])) {
|
|
|
|
|
foreach ($entry['deleted_task_id_list'] as $taskId) {
|
|
|
|
|
$output->writeln("<info>\t - " . 'Deleted task '. $taskId . ' from the database</info>');
|
|
|
|
|
}
|
2025-08-06 09:34:15 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
}
|