Browse Source
Merge pull request #54272 from nextcloud/enh/noid/taskprocessing-task-add-cleanup-flag
Merge pull request #54272 from nextcloud/enh/noid/taskprocessing-task-add-cleanup-flag
feat(taskprocessing): add cleanup flag to tasksrefresh-ldap-user-on-login
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
23 changed files with 345 additions and 83 deletions
-
93core/Command/TaskProcessing/Cleanup.php
-
2core/Command/TaskProcessing/EnabledCommand.php
-
2core/Command/TaskProcessing/GetCommand.php
-
2core/Command/TaskProcessing/ListCommand.php
-
2core/Command/TaskProcessing/Statistics.php
-
42core/Controller/TaskProcessingApiController.php
-
49core/Migrations/Version32000Date20250806110519.php
-
1core/ResponseDefinitions.php
-
6core/openapi-ex_app.json
-
6core/openapi-full.json
-
6core/openapi.json
-
1core/register_command.php
-
2lib/composer/composer/autoload_classmap.php
-
2lib/composer/composer/autoload_static.php
-
10lib/private/TaskProcessing/Db/Task.php
-
25lib/private/TaskProcessing/Db/TaskMapper.php
-
94lib/private/TaskProcessing/Manager.php
-
44lib/private/TaskProcessing/RemoveOldTasksBackgroundJob.php
-
10lib/public/TaskProcessing/IManager.php
-
20lib/public/TaskProcessing/Task.php
-
6openapi.json
-
1tests/lib/TaskProcessing/TaskProcessingTest.php
-
2version.php
@ -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; |
|||
} |
|||
} |
|||
@ -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; |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue