Skip to content

Commit

Permalink
fix(TaskProcessing): Set task status to running when processing via I…
Browse files Browse the repository at this point in the history
…SynchronousProvider

Signed-off-by: Marcel Klehr <mklehr@gmx.net>
  • Loading branch information
marcelklehr committed Jul 4, 2024
1 parent 0116a63 commit 1b2c8d5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/private/TaskProcessing/Manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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;
Expand Down Expand Up @@ -870,4 +871,14 @@ public function lockTask(Task $task): bool {
$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);
}
}
2 changes: 2 additions & 0 deletions lib/private/TaskProcessing/SynchronousBackgroundJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
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 {
Expand Down Expand Up @@ -61,6 +62,7 @@ protected function run($argument) {
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]);
Expand Down
10 changes: 10 additions & 0 deletions lib/public/TaskProcessing/IManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,14 @@ public function prepareInputData(Task $task): array;
* @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;
}

0 comments on commit 1b2c8d5

Please sign in to comment.