Skip to content

Commit

Permalink
feat(taskprocessing): new command to get a task from a task ID, inclu…
Browse files Browse the repository at this point in the history
…de error_message in list and get commands

Signed-off-by: Julien Veyssier <[email protected]>
  • Loading branch information
julien-nc committed Oct 1, 2024
1 parent 2676217 commit 39e64e1
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 1 deletion.
41 changes: 41 additions & 0 deletions core/Command/TaskProcessing/GetCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OC\Core\Command\TaskProcessing;

use OC\Core\Command\Base;
use OCP\TaskProcessing\IManager;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class GetCommand extends Base {
public function __construct(
protected IManager $taskProcessingManager,
) {
parent::__construct();
}

protected function configure() {
$this
->setName('taskprocessing:task:get')
->setDescription('get task')
->addArgument(
'task-id',
InputArgument::REQUIRED,
'User for whom the addressbook will be created'
);
parent::configure();
}

protected function execute(InputInterface $input, OutputInterface $output): int {
$taskId = (int)$input->getArgument('task-id');
$task = $this->taskProcessingManager->getTask($taskId);
$jsonTask = $task->jsonSerialize();
$jsonTask['error_message'] = $task->getErrorMessage();
$this->writeArrayInOutputFormat($input, $output, $jsonTask);
return 0;
}
}
6 changes: 5 additions & 1 deletion core/Command/TaskProcessing/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$endedBefore = $input->getOption('endedBefore');

$tasks = $this->taskProcessingManager->getTasks($userIdFilter, $type, $appId, $customId, $status, $scheduledAfter, $endedBefore);
$arrayTasks = array_map(fn (Task $task): array => $task->jsonSerialize(), $tasks);
$arrayTasks = array_map(static function (Task $task) {
$jsonTask = $task->jsonSerialize();
$jsonTask['error_message'] = $task->getErrorMessage();
return $jsonTask;
}, $tasks);

$this->writeArrayInOutputFormat($input, $output, $arrayTasks);
return 0;
Expand Down
1 change: 1 addition & 0 deletions core/register_command.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
$application->add(Server::get(Command\SetupChecks::class));
$application->add(Server::get(Command\FilesMetadata\Get::class));

$application->add(Server::get(Command\TaskProcessing\GetCommand::class));
$application->add(Server::get(Command\TaskProcessing\ListCommand::class));
$application->add(Server::get(Command\TaskProcessing\Statistics::class));

Expand Down
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,7 @@
'OC\\Core\\Command\\SystemTag\\Delete' => $baseDir . '/core/Command/SystemTag/Delete.php',
'OC\\Core\\Command\\SystemTag\\Edit' => $baseDir . '/core/Command/SystemTag/Edit.php',
'OC\\Core\\Command\\SystemTag\\ListCommand' => $baseDir . '/core/Command/SystemTag/ListCommand.php',
'OC\\Core\\Command\\TaskProcessing\\GetCommand' => $baseDir . '/core/Command/TaskProcessing/GetCommand.php',
'OC\\Core\\Command\\TaskProcessing\\ListCommand' => $baseDir . '/core/Command/TaskProcessing/ListCommand.php',
'OC\\Core\\Command\\TaskProcessing\\Statistics' => $baseDir . '/core/Command/TaskProcessing/Statistics.php',
'OC\\Core\\Command\\TwoFactorAuth\\Base' => $baseDir . '/core/Command/TwoFactorAuth/Base.php',
Expand Down
1 change: 1 addition & 0 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -1261,6 +1261,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OC\\Core\\Command\\SystemTag\\Delete' => __DIR__ . '/../../..' . '/core/Command/SystemTag/Delete.php',
'OC\\Core\\Command\\SystemTag\\Edit' => __DIR__ . '/../../..' . '/core/Command/SystemTag/Edit.php',
'OC\\Core\\Command\\SystemTag\\ListCommand' => __DIR__ . '/../../..' . '/core/Command/SystemTag/ListCommand.php',
'OC\\Core\\Command\\TaskProcessing\\GetCommand' => __DIR__ . '/../../..' . '/core/Command/TaskProcessing/GetCommand.php',
'OC\\Core\\Command\\TaskProcessing\\ListCommand' => __DIR__ . '/../../..' . '/core/Command/TaskProcessing/ListCommand.php',
'OC\\Core\\Command\\TaskProcessing\\Statistics' => __DIR__ . '/../../..' . '/core/Command/TaskProcessing/Statistics.php',
'OC\\Core\\Command\\TwoFactorAuth\\Base' => __DIR__ . '/../../..' . '/core/Command/TwoFactorAuth/Base.php',
Expand Down

0 comments on commit 39e64e1

Please sign in to comment.