Skip to content

Commit 3411631

Browse files
committed
feat(taskprocessing): use Generator::getReturn to get the list of deleted tasks in the cleanup command
Signed-off-by: Julien Veyssier <[email protected]>
1 parent c4cf047 commit 3411631

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

core/Command/TaskProcessing/Cleanup.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,19 @@ protected function configure() {
3434

3535
protected function execute(InputInterface $input, OutputInterface $output): int {
3636
$maxAgeSeconds = $input->getArgument('maxAgeSeconds') ?? Manager::MAX_TASK_AGE_SECONDS;
37-
$output->writeln('Cleanup up tasks older than '. $maxAgeSeconds . ' seconds and the related output files');
37+
$output->writeln('<comment>Cleanup up tasks older than '. $maxAgeSeconds . ' seconds and the related output files</comment>');
3838
$cleanupResult = $this->taskProcessingManager->cleanupOldTasks($maxAgeSeconds);
3939
foreach ($cleanupResult as $entry) {
4040
if (isset($entry['task_id'], $entry['file_id'], $entry['file_name'])) {
41-
$output->writeln("\t - " . 'Deleted appData/core/TaskProcessing/' . $entry['file_name'] . '(fileId: ' . $entry['file_id'] . ', taskId: ' . $entry['task_id'] . ')');
41+
$output->writeln("<info>\t - " . 'Deleted appData/core/TaskProcessing/' . $entry['file_name'] . ' (fileId: ' . $entry['file_id'] . ', taskId: ' . $entry['task_id'] . ')</info>');
4242
} elseif (isset($entry['directory_name'])) {
43-
$output->writeln("\t - " . 'Deleted appData/core/'. $entry['directory_name'] . '/' . $entry['file_name']);
43+
$output->writeln("<info>\t - " . 'Deleted appData/core/'. $entry['directory_name'] . '/' . $entry['file_name'] . '</info>');
4444
} elseif (isset($entry['deleted_task_count'])) {
45-
$output->writeln("\t - " . 'Deleted '. $entry['deleted_task_count'] . ' tasks from the database');
45+
$output->writeln("<comment>\t - " . 'Deleted '. $entry['deleted_task_count'] . ' tasks from the database</comment>');
46+
} elseif (isset($entry['deleted_task_id_list'])) {
47+
foreach ($entry['deleted_task_id_list'] as $taskId) {
48+
$output->writeln("<info>\t - " . 'Deleted task '. $taskId . ' from the database</info>');
49+
}
4650
}
4751
}
4852
return 0;

lib/private/TaskProcessing/Manager.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1495,15 +1495,19 @@ public function extractFileIdsFromTask(Task $task): array {
14951495
* @return \Generator
14961496
*/
14971497
public function cleanupOldTasks(int $ageInSeconds = self::MAX_TASK_AGE_SECONDS): \Generator {
1498+
$taskIdsToCleanup = [];
14981499
try {
1499-
foreach ($this->cleanupTaskProcessingTaskFiles($ageInSeconds) as $cleanedUpEntry) {
1500+
$fileCleanupGenerator = $this->cleanupTaskProcessingTaskFiles($ageInSeconds);
1501+
foreach ($fileCleanupGenerator as $cleanedUpEntry) {
15001502
yield $cleanedUpEntry;
15011503
}
1504+
$taskIdsToCleanup = $fileCleanupGenerator->getReturn();
15021505
} catch (\Exception $e) {
15031506
$this->logger->warning('Failed to delete stale task processing tasks files', ['exception' => $e]);
15041507
}
15051508
try {
15061509
$deletedTaskCount = $this->taskMapper->deleteOlderThan($ageInSeconds);
1510+
yield ['deleted_task_id_list' => $taskIdsToCleanup];
15071511
yield ['deleted_task_count' => $deletedTaskCount];
15081512
} catch (\OCP\DB\Exception $e) {
15091513
$this->logger->warning('Failed to delete stale task processing tasks', ['exception' => $e]);
@@ -1555,7 +1559,9 @@ private function clearFilesOlderThan(ISimpleFolder $folder, int $ageInSeconds):
15551559
* @throws \OCP\Files\NotFoundException
15561560
*/
15571561
private function cleanupTaskProcessingTaskFiles(int $ageInSeconds): \Generator {
1562+
$taskIdsToCleanup = [];
15581563
foreach ($this->taskMapper->getTasksToCleanup($ageInSeconds) as $task) {
1564+
$taskIdsToCleanup[] = $task->getId();
15591565
$ocpTask = $task->toPublicTask();
15601566
$fileIds = $this->extractFileIdsFromTask($ocpTask);
15611567
foreach ($fileIds as $fileId) {
@@ -1573,6 +1579,7 @@ private function cleanupTaskProcessingTaskFiles(int $ageInSeconds): \Generator {
15731579
}
15741580
}
15751581
}
1582+
return $taskIdsToCleanup;
15761583
}
15771584

15781585
/**

0 commit comments

Comments
 (0)