mirror of
https://github.com/nextcloud/server.git
synced 2026-04-22 23:03:00 -04:00
feat(taskprocessing): use Generator::getReturn to get the list of deleted tasks in the cleanup command
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
This commit is contained in:
parent
19801f7ec4
commit
cc295f2452
2 changed files with 16 additions and 5 deletions
|
|
@ -34,15 +34,19 @@ class Cleanup extends Base {
|
|||
|
||||
protected function execute(InputInterface $input, OutputInterface $output): int {
|
||||
$maxAgeSeconds = $input->getArgument('maxAgeSeconds') ?? Manager::MAX_TASK_AGE_SECONDS;
|
||||
$output->writeln('Cleanup up tasks older than '. $maxAgeSeconds . ' seconds and the related output files');
|
||||
$output->writeln('<comment>Cleanup up tasks older than '. $maxAgeSeconds . ' seconds and the related output files</comment>');
|
||||
$cleanupResult = $this->taskProcessingManager->cleanupOldTasks($maxAgeSeconds);
|
||||
foreach ($cleanupResult as $entry) {
|
||||
if (isset($entry['task_id'], $entry['file_id'], $entry['file_name'])) {
|
||||
$output->writeln("\t - " . 'Deleted appData/core/TaskProcessing/' . $entry['file_name'] . '(fileId: ' . $entry['file_id'] . ', taskId: ' . $entry['task_id'] . ')');
|
||||
$output->writeln("<info>\t - " . 'Deleted appData/core/TaskProcessing/' . $entry['file_name'] . ' (fileId: ' . $entry['file_id'] . ', taskId: ' . $entry['task_id'] . ')</info>');
|
||||
} elseif (isset($entry['directory_name'])) {
|
||||
$output->writeln("\t - " . 'Deleted appData/core/'. $entry['directory_name'] . '/' . $entry['file_name']);
|
||||
$output->writeln("<info>\t - " . 'Deleted appData/core/'. $entry['directory_name'] . '/' . $entry['file_name'] . '</info>');
|
||||
} elseif (isset($entry['deleted_task_count'])) {
|
||||
$output->writeln("\t - " . 'Deleted '. $entry['deleted_task_count'] . ' tasks from the database');
|
||||
$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>');
|
||||
}
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -1495,15 +1495,19 @@ class Manager implements IManager {
|
|||
* @return \Generator
|
||||
*/
|
||||
public function cleanupOldTasks(int $ageInSeconds = self::MAX_TASK_AGE_SECONDS): \Generator {
|
||||
$taskIdsToCleanup = [];
|
||||
try {
|
||||
foreach ($this->cleanupTaskProcessingTaskFiles($ageInSeconds) as $cleanedUpEntry) {
|
||||
$fileCleanupGenerator = $this->cleanupTaskProcessingTaskFiles($ageInSeconds);
|
||||
foreach ($fileCleanupGenerator as $cleanedUpEntry) {
|
||||
yield $cleanedUpEntry;
|
||||
}
|
||||
$taskIdsToCleanup = $fileCleanupGenerator->getReturn();
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->warning('Failed to delete stale task processing tasks files', ['exception' => $e]);
|
||||
}
|
||||
try {
|
||||
$deletedTaskCount = $this->taskMapper->deleteOlderThan($ageInSeconds);
|
||||
yield ['deleted_task_id_list' => $taskIdsToCleanup];
|
||||
yield ['deleted_task_count' => $deletedTaskCount];
|
||||
} catch (\OCP\DB\Exception $e) {
|
||||
$this->logger->warning('Failed to delete stale task processing tasks', ['exception' => $e]);
|
||||
|
|
@ -1555,7 +1559,9 @@ class Manager implements IManager {
|
|||
* @throws \OCP\Files\NotFoundException
|
||||
*/
|
||||
private function cleanupTaskProcessingTaskFiles(int $ageInSeconds): \Generator {
|
||||
$taskIdsToCleanup = [];
|
||||
foreach ($this->taskMapper->getTasksToCleanup($ageInSeconds) as $task) {
|
||||
$taskIdsToCleanup[] = $task->getId();
|
||||
$ocpTask = $task->toPublicTask();
|
||||
$fileIds = $this->extractFileIdsFromTask($ocpTask);
|
||||
foreach ($fileIds as $fileId) {
|
||||
|
|
@ -1573,6 +1579,7 @@ class Manager implements IManager {
|
|||
}
|
||||
}
|
||||
}
|
||||
return $taskIdsToCleanup;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue