diff --git a/core/Command/TaskProcessing/Cleanup.php b/core/Command/TaskProcessing/Cleanup.php
index bcf3140ba35..bec4639f645 100644
--- a/core/Command/TaskProcessing/Cleanup.php
+++ b/core/Command/TaskProcessing/Cleanup.php
@@ -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('Cleanup up tasks older than '. $maxAgeSeconds . ' seconds and the related output files');
$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("\t - " . 'Deleted appData/core/TaskProcessing/' . $entry['file_name'] . ' (fileId: ' . $entry['file_id'] . ', taskId: ' . $entry['task_id'] . ')');
} elseif (isset($entry['directory_name'])) {
- $output->writeln("\t - " . 'Deleted appData/core/'. $entry['directory_name'] . '/' . $entry['file_name']);
+ $output->writeln("\t - " . 'Deleted appData/core/'. $entry['directory_name'] . '/' . $entry['file_name'] . '');
} elseif (isset($entry['deleted_task_count'])) {
- $output->writeln("\t - " . 'Deleted '. $entry['deleted_task_count'] . ' tasks from the database');
+ $output->writeln("\t - " . 'Deleted '. $entry['deleted_task_count'] . ' tasks from the database');
+ } elseif (isset($entry['deleted_task_id_list'])) {
+ foreach ($entry['deleted_task_id_list'] as $taskId) {
+ $output->writeln("\t - " . 'Deleted task '. $taskId . ' from the database');
+ }
}
}
return 0;
diff --git a/lib/private/TaskProcessing/Manager.php b/lib/private/TaskProcessing/Manager.php
index db2561da6b8..bc37bb04651 100644
--- a/lib/private/TaskProcessing/Manager.php
+++ b/lib/private/TaskProcessing/Manager.php
@@ -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;
}
/**