Skip to content

Commit 14cf5b0

Browse files
committed
feat(taskprocessing): new command to get a task from a task ID, include error_message in list and get commands
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
1 parent 2676217 commit 14cf5b0

File tree

5 files changed

+49
-1
lines changed

5 files changed

+49
-1
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
/**
3+
* SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
4+
* SPDX-License-Identifier: AGPL-3.0-or-later
5+
*/
6+
namespace OC\Core\Command\TaskProcessing;
7+
8+
use OC\Core\Command\Base;
9+
use OCP\TaskProcessing\IManager;
10+
use Symfony\Component\Console\Input\InputArgument;
11+
use Symfony\Component\Console\Input\InputInterface;
12+
use Symfony\Component\Console\Output\OutputInterface;
13+
14+
class GetCommand extends Base {
15+
public function __construct(
16+
protected IManager $taskProcessingManager,
17+
) {
18+
parent::__construct();
19+
}
20+
21+
protected function configure() {
22+
$this
23+
->setName('taskprocessing:task:get')
24+
->setDescription('Display all information for a specific task')
25+
->addArgument(
26+
'task-id',
27+
InputArgument::REQUIRED,
28+
'ID of the task to display'
29+
);
30+
parent::configure();
31+
}
32+
33+
protected function execute(InputInterface $input, OutputInterface $output): int {
34+
$taskId = (int)$input->getArgument('task-id');
35+
$task = $this->taskProcessingManager->getTask($taskId);
36+
$jsonTask = $task->jsonSerialize();
37+
$jsonTask['error_message'] = $task->getErrorMessage();
38+
$this->writeArrayInOutputFormat($input, $output, $jsonTask);
39+
return 0;
40+
}
41+
}

core/Command/TaskProcessing/ListCommand.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8383
$endedBefore = $input->getOption('endedBefore');
8484

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

8892
$this->writeArrayInOutputFormat($input, $output, $arrayTasks);
8993
return 0;

core/register_command.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@
145145
$application->add(Server::get(Command\SetupChecks::class));
146146
$application->add(Server::get(Command\FilesMetadata\Get::class));
147147

148+
$application->add(Server::get(Command\TaskProcessing\GetCommand::class));
148149
$application->add(Server::get(Command\TaskProcessing\ListCommand::class));
149150
$application->add(Server::get(Command\TaskProcessing\Statistics::class));
150151

lib/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,7 @@
12281228
'OC\\Core\\Command\\SystemTag\\Delete' => $baseDir . '/core/Command/SystemTag/Delete.php',
12291229
'OC\\Core\\Command\\SystemTag\\Edit' => $baseDir . '/core/Command/SystemTag/Edit.php',
12301230
'OC\\Core\\Command\\SystemTag\\ListCommand' => $baseDir . '/core/Command/SystemTag/ListCommand.php',
1231+
'OC\\Core\\Command\\TaskProcessing\\GetCommand' => $baseDir . '/core/Command/TaskProcessing/GetCommand.php',
12311232
'OC\\Core\\Command\\TaskProcessing\\ListCommand' => $baseDir . '/core/Command/TaskProcessing/ListCommand.php',
12321233
'OC\\Core\\Command\\TaskProcessing\\Statistics' => $baseDir . '/core/Command/TaskProcessing/Statistics.php',
12331234
'OC\\Core\\Command\\TwoFactorAuth\\Base' => $baseDir . '/core/Command/TwoFactorAuth/Base.php',

lib/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,6 +1261,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
12611261
'OC\\Core\\Command\\SystemTag\\Delete' => __DIR__ . '/../../..' . '/core/Command/SystemTag/Delete.php',
12621262
'OC\\Core\\Command\\SystemTag\\Edit' => __DIR__ . '/../../..' . '/core/Command/SystemTag/Edit.php',
12631263
'OC\\Core\\Command\\SystemTag\\ListCommand' => __DIR__ . '/../../..' . '/core/Command/SystemTag/ListCommand.php',
1264+
'OC\\Core\\Command\\TaskProcessing\\GetCommand' => __DIR__ . '/../../..' . '/core/Command/TaskProcessing/GetCommand.php',
12641265
'OC\\Core\\Command\\TaskProcessing\\ListCommand' => __DIR__ . '/../../..' . '/core/Command/TaskProcessing/ListCommand.php',
12651266
'OC\\Core\\Command\\TaskProcessing\\Statistics' => __DIR__ . '/../../..' . '/core/Command/TaskProcessing/Statistics.php',
12661267
'OC\\Core\\Command\\TwoFactorAuth\\Base' => __DIR__ . '/../../..' . '/core/Command/TwoFactorAuth/Base.php',

0 commit comments

Comments
 (0)