Skip to content

Commit 2c8a51f

Browse files
committed
fix(TaskProcessing): Set task status to running when processing via ISynchronousProvider
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
1 parent 05bdafa commit 2c8a51f

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

lib/private/TaskProcessing/Manager.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use OCP\AppFramework\Db\DoesNotExistException;
1616
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
1717
use OCP\BackgroundJob\IJobList;
18+
use OCP\DB\Exception;
1819
use OCP\EventDispatcher\IEventDispatcher;
1920
use OCP\Files\AppData\IAppDataFactory;
2021
use OCP\Files\File;
@@ -870,4 +871,14 @@ public function lockTask(Task $task): bool {
870871
$task->setStatus(Task::STATUS_RUNNING);
871872
return true;
872873
}
874+
875+
/**
876+
* @throws \JsonException
877+
* @throws Exception
878+
*/
879+
public function setTaskStatus(Task $task, int $status): void {
880+
$task->setStatus($status);
881+
$taskEntity = \OC\TaskProcessing\Db\Task::fromPublicTask($task);
882+
$this->taskMapper->update($taskEntity);
883+
}
873884
}

lib/private/TaskProcessing/SynchronousBackgroundJob.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use OCP\TaskProcessing\Exception\ValidationException;
1919
use OCP\TaskProcessing\IManager;
2020
use OCP\TaskProcessing\ISynchronousProvider;
21+
use OCP\TaskProcessing\Task;
2122
use Psr\Log\LoggerInterface;
2223

2324
class SynchronousBackgroundJob extends QueuedJob {
@@ -61,6 +62,7 @@ protected function run($argument) {
6162
return;
6263
}
6364
try {
65+
$this->taskProcessingManager->setTaskStatus($task, Task::STATUS_RUNNING);
6466
$output = $provider->process($task->getUserId(), $input, fn (float $progress) => $this->taskProcessingManager->setTaskProgress($task->getId(), $progress));
6567
} catch (ProcessingException $e) {
6668
$this->logger->warning('Failed to process a TaskProcessing task with synchronous provider ' . $provider->getId(), ['exception' => $e]);

lib/public/TaskProcessing/IManager.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,14 @@ public function prepareInputData(Task $task): array;
172172
* @since 30.0.0
173173
*/
174174
public function lockTask(Task $task): bool;
175+
176+
/**
177+
* @param Task $task
178+
* @psalm-param Task::STATUS_* $status
179+
* @param int $status
180+
* @throws \JsonException
181+
* @throws Exception
182+
* @since 30.0.0
183+
*/
184+
public function setTaskStatus(Task $task, int $status): void;
175185
}

0 commit comments

Comments
 (0)