fix(TaskProcessing): Set task status to running when processing via ISynchronousProvider

Signed-off-by: Marcel Klehr <mklehr@gmx.net>
This commit is contained in:
Marcel Klehr 2024-07-03 16:08:13 +02:00
parent 0116a631c6
commit 1b2c8d5030
3 changed files with 23 additions and 0 deletions

View file

@ -15,6 +15,7 @@ use OC\TaskProcessing\Db\TaskMapper;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\BackgroundJob\IJobList;
use OCP\DB\Exception;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Files\AppData\IAppDataFactory;
use OCP\Files\File;
@ -870,4 +871,14 @@ class Manager implements IManager {
$task->setStatus(Task::STATUS_RUNNING);
return true;
}
/**
* @throws \JsonException
* @throws Exception
*/
public function setTaskStatus(Task $task, int $status): void {
$task->setStatus($status);
$taskEntity = \OC\TaskProcessing\Db\Task::fromPublicTask($task);
$this->taskMapper->update($taskEntity);
}
}

View file

@ -18,6 +18,7 @@ use OCP\TaskProcessing\Exception\ProcessingException;
use OCP\TaskProcessing\Exception\ValidationException;
use OCP\TaskProcessing\IManager;
use OCP\TaskProcessing\ISynchronousProvider;
use OCP\TaskProcessing\Task;
use Psr\Log\LoggerInterface;
class SynchronousBackgroundJob extends QueuedJob {
@ -61,6 +62,7 @@ class SynchronousBackgroundJob extends QueuedJob {
return;
}
try {
$this->taskProcessingManager->setTaskStatus($task, Task::STATUS_RUNNING);
$output = $provider->process($task->getUserId(), $input, fn (float $progress) => $this->taskProcessingManager->setTaskProgress($task->getId(), $progress));
} catch (ProcessingException $e) {
$this->logger->warning('Failed to process a TaskProcessing task with synchronous provider ' . $provider->getId(), ['exception' => $e]);

View file

@ -172,4 +172,14 @@ interface IManager {
* @since 30.0.0
*/
public function lockTask(Task $task): bool;
/**
* @param Task $task
* @psalm-param Task::STATUS_* $status
* @param int $status
* @throws \JsonException
* @throws Exception
* @since 30.0.0
*/
public function setTaskStatus(Task $task, int $status): void;
}