-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
feat(taskprocessing): add cleanup flag to tasks #54272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kesselb
merged 10 commits into
master
from
enh/noid/taskprocessing-task-add-cleanup-flag
Aug 15, 2025
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8c52b6c
feat(taskprocessing): add cleanup flag to tasks to decide if they sho…
julien-nc e6adbd9
feat(taskprocessing): generate OpenAPI specs, fix lint issue, fix tests
julien-nc 19801f7
feat(taskprocessing): move cleanup method to private taskprocessing m…
julien-nc cc295f2
feat(taskprocessing): use Generator::getReturn to get the list of del…
julien-nc 10921c0
feat(taskprocessing): fix some CI
julien-nc 0dc93bc
feat(taskprocessing): fix phpunit tests
julien-nc 2b9af82
feat(taskprocessing): add strict types to all taskprocessing command …
julien-nc 222b19b
feat(taskprocessing): rename cleanup column to allow_cleanup
julien-nc e2c65b2
feat(taskprocessing): fix mistake
julien-nc aa2ca86
feat(taskprocessing): avoid generator cascade
julien-nc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * 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\Db\TaskMapper; | ||
| use OC\TaskProcessing\Manager; | ||
| use OCP\Files\AppData\IAppDataFactory; | ||
| use Psr\Log\LoggerInterface; | ||
| use Symfony\Component\Console\Input\InputArgument; | ||
| use Symfony\Component\Console\Input\InputInterface; | ||
| use Symfony\Component\Console\Output\OutputInterface; | ||
|
|
||
| class Cleanup extends Base { | ||
| private \OCP\Files\IAppData $appData; | ||
|
|
||
| public function __construct( | ||
| protected Manager $taskProcessingManager, | ||
| private TaskMapper $taskMapper, | ||
| private LoggerInterface $logger, | ||
| IAppDataFactory $appDataFactory, | ||
| ) { | ||
| parent::__construct(); | ||
| $this->appData = $appDataFactory->get('core'); | ||
| } | ||
|
|
||
| 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; | ||
| $output->writeln('<comment>Cleanup up tasks older than ' . $maxAgeSeconds . ' seconds and the related output files</comment>'); | ||
|
|
||
| $taskIdsToCleanup = []; | ||
| try { | ||
| $fileCleanupGenerator = $this->taskProcessingManager->cleanupTaskProcessingTaskFiles($maxAgeSeconds); | ||
| foreach ($fileCleanupGenerator as $cleanedUpEntry) { | ||
| $output->writeln( | ||
| "<info>\t - " . 'Deleted appData/core/TaskProcessing/' . $cleanedUpEntry['file_name'] | ||
| . ' (fileId: ' . $cleanedUpEntry['file_id'] . ', taskId: ' . $cleanedUpEntry['task_id'] . ')</info>' | ||
| ); | ||
| } | ||
| $taskIdsToCleanup = $fileCleanupGenerator->getReturn(); | ||
| } catch (\Exception $e) { | ||
| $this->logger->warning('Failed to delete stale task processing tasks files', ['exception' => $e]); | ||
| $output->writeln('<warning>Failed to delete stale task processing tasks files</warning>'); | ||
| } | ||
| try { | ||
| $deletedTaskCount = $this->taskMapper->deleteOlderThan($maxAgeSeconds); | ||
| foreach ($taskIdsToCleanup as $taskId) { | ||
| $output->writeln("<info>\t - " . 'Deleted task ' . $taskId . ' from the database</info>'); | ||
| } | ||
| $output->writeln("<comment>\t - " . 'Deleted ' . $deletedTaskCount . ' tasks from the database</comment>'); | ||
| } catch (\OCP\DB\Exception $e) { | ||
| $this->logger->warning('Failed to delete stale task processing tasks', ['exception' => $e]); | ||
| $output->writeln('<warning>Failed to delete stale task processing tasks</warning>'); | ||
| } | ||
| try { | ||
| $textToImageDeletedFileNames = $this->taskProcessingManager->clearFilesOlderThan($this->appData->getFolder('text2image'), $maxAgeSeconds); | ||
| foreach ($textToImageDeletedFileNames as $entry) { | ||
| $output->writeln("<info>\t - " . 'Deleted appData/core/text2image/' . $entry . '</info>'); | ||
| } | ||
| } catch (\OCP\Files\NotFoundException $e) { | ||
| // noop | ||
| } | ||
| try { | ||
| $audioToTextDeletedFileNames = $this->taskProcessingManager->clearFilesOlderThan($this->appData->getFolder('audio2text'), $maxAgeSeconds); | ||
| foreach ($audioToTextDeletedFileNames as $entry) { | ||
| $output->writeln("<info>\t - " . 'Deleted appData/core/audio2text/' . $entry . '</info>'); | ||
| } | ||
| } catch (\OCP\Files\NotFoundException $e) { | ||
| // noop | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
| namespace OC\Core\Migrations; | ||
|
|
||
| use Closure; | ||
| use OCP\DB\ISchemaWrapper; | ||
| use OCP\DB\Types; | ||
| use OCP\Migration\Attributes\AddColumn; | ||
| use OCP\Migration\Attributes\ColumnType; | ||
| use OCP\Migration\IOutput; | ||
| use OCP\Migration\SimpleMigrationStep; | ||
|
|
||
| /** | ||
| * | ||
| */ | ||
| #[AddColumn(table: 'taskprocessing_tasks', name: 'allow_cleanup', type: ColumnType::SMALLINT)] | ||
| class Version32000Date20250806110519 extends SimpleMigrationStep { | ||
|
|
||
| /** | ||
| * @param IOutput $output | ||
| * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` | ||
| * @param array $options | ||
| * @return null|ISchemaWrapper | ||
| */ | ||
| public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { | ||
| /** @var ISchemaWrapper $schema */ | ||
| $schema = $schemaClosure(); | ||
|
|
||
| if ($schema->hasTable('taskprocessing_tasks')) { | ||
| $table = $schema->getTable('taskprocessing_tasks'); | ||
| if (!$table->hasColumn('allow_cleanup')) { | ||
| $table->addColumn('allow_cleanup', Types::SMALLINT, [ | ||
| 'notnull' => true, | ||
| 'default' => 1, | ||
| 'unsigned' => true, | ||
| ]); | ||
| return $schema; | ||
| } | ||
| } | ||
|
|
||
| return null; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.