Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat(taskprocessing): use Generator::getReturn to get the list of del…
…eted tasks in the cleanup command

Signed-off-by: Julien Veyssier <[email protected]>
  • Loading branch information
julien-nc committed Aug 7, 2025
commit cc295f2452c29baa4b8ba653fcd480b64eb1eaf5
12 changes: 8 additions & 4 deletions core/Command/TaskProcessing/Cleanup.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,19 @@ protected function configure() {

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;
Expand Down
9 changes: 8 additions & 1 deletion lib/private/TaskProcessing/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -1495,15 +1495,19 @@ public function extractFileIdsFromTask(Task $task): array {
* @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]);
Expand Down Expand Up @@ -1555,7 +1559,9 @@ private function clearFilesOlderThan(ISimpleFolder $folder, int $ageInSeconds):
* @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) {
Expand All @@ -1573,6 +1579,7 @@ private function cleanupTaskProcessingTaskFiles(int $ageInSeconds): \Generator {
}
}
}
return $taskIdsToCleanup;
}

/**
Expand Down