diff options
author | Marcel Klehr <mklehr@gmx.net> | 2024-05-06 13:03:03 +0200 |
---|---|---|
committer | Marcel Klehr <mklehr@gmx.net> | 2024-05-14 11:38:40 +0200 |
commit | 2c878099f1d2fbfc5b5d117c63fa8723d3e26f3d (patch) | |
tree | 7440a3171dc15a07cf296ddf3461d18862b70fbe | |
parent | 5de42a53e263d6dda1896ff223158646bd81867b (diff) | |
download | nextcloud-server-2c878099f1d2fbfc5b5d117c63fa8723d3e26f3d.tar.gz nextcloud-server-2c878099f1d2fbfc5b5d117c63fa8723d3e26f3d.zip |
fix: address review comments
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
-rw-r--r-- | core/Controller/TaskProcessingApiController.php | 20 | ||||
-rw-r--r-- | core/ResponseDefinitions.php | 2 | ||||
-rw-r--r-- | core/openapi.json | 3 | ||||
-rw-r--r-- | lib/private/TaskProcessing/Db/Task.php | 4 | ||||
-rw-r--r-- | lib/private/TaskProcessing/Manager.php | 6 | ||||
-rw-r--r-- | lib/private/TaskProcessing/RemoveOldTasksBackgroundJob.php | 8 |
6 files changed, 30 insertions, 13 deletions
diff --git a/core/Controller/TaskProcessingApiController.php b/core/Controller/TaskProcessingApiController.php index e42e03424b8..2195d780f45 100644 --- a/core/Controller/TaskProcessingApiController.php +++ b/core/Controller/TaskProcessingApiController.php @@ -183,9 +183,9 @@ class TaskProcessingApiController extends \OCP\AppFramework\OCSController { $this->taskProcessingManager->deleteTask($task); - return new DataResponse([]); + return new DataResponse(null); } catch (\OCP\TaskProcessing\Exception\NotFoundException $e) { - return new DataResponse([]); + return new DataResponse(null); } catch (\OCP\TaskProcessing\Exception\Exception $e) { return new DataResponse(['message' => $this->l->t('Internal error')], Http::STATUS_INTERNAL_SERVER_ERROR); } @@ -272,20 +272,22 @@ class TaskProcessingApiController extends \OCP\AppFramework\OCSController { $taskType = $taskTypes[$task->getTaskTypeId()]; foreach ($taskType['inputShape'] + $taskType['optionalInputShape'] as $key => $descriptor) { if (in_array(EShapeType::getScalarType($descriptor->getShapeType()), [EShapeType::File, EShapeType::Image, EShapeType::Audio, EShapeType::Video], true)) { - if (is_array($task->getInput()[$key])) { - $ids += $task->getInput()[$key]; + $inputSlot = $task->getInput()[$key]; + if (is_array($inputSlot)) { + $ids += $inputSlot; } else { - $ids[] = $task->getInput()[$key]; + $ids[] = $inputSlot; } } } if ($task->getOutput() !== null) { foreach ($taskType['outputShape'] + $taskType['optionalOutputShape'] as $key => $descriptor) { if (in_array(EShapeType::getScalarType($descriptor->getShapeType()), [EShapeType::File, EShapeType::Image, EShapeType::Audio, EShapeType::Video], true)) { - if (is_array($task->getInput()[$key])) { - $ids += $task->getOutput()[$key]; + $outputSlot = $task->getOutput()[$key]; + if (is_array($outputSlot)) { + $ids += $outputSlot; } else { - $ids[] = $task->getOutput()[$key]; + $ids[] = $outputSlot; } } } @@ -338,7 +340,9 @@ class TaskProcessingApiController extends \OCP\AppFramework\OCSController { #[ApiRoute(verb: 'POST', url: '/tasks/{taskId}/result', root: '/taskprocessing')] public function setResult(int $taskId, ?array $output = null, ?string $errorMessage = null): DataResponse { try { + // Check if the current user can access the task $this->taskProcessingManager->getUserTask($taskId, $this->userId); + // set result $this->taskProcessingManager->setTaskResult($taskId, $errorMessage, $output); $task = $this->taskProcessingManager->getUserTask($taskId, $this->userId); diff --git a/core/ResponseDefinitions.php b/core/ResponseDefinitions.php index 68474a6e535..75e307e455c 100644 --- a/core/ResponseDefinitions.php +++ b/core/ResponseDefinitions.php @@ -193,7 +193,7 @@ namespace OCA\Core; * } * * @psalm-type CoreTaskProcessingTask = array{ - * id: ?int, + * id: int, * type: string, * status: 0|1|2|3|4|5, * userId: ?string, diff --git a/core/openapi.json b/core/openapi.json index ef2378d4e4e..8adaae0668a 100644 --- a/core/openapi.json +++ b/core/openapi.json @@ -503,8 +503,7 @@ "properties": { "id": { "type": "integer", - "format": "int64", - "nullable": true + "format": "int64" }, "type": { "type": "string" diff --git a/lib/private/TaskProcessing/Db/Task.php b/lib/private/TaskProcessing/Db/Task.php index a506ffd86c9..6e181285c90 100644 --- a/lib/private/TaskProcessing/Db/Task.php +++ b/lib/private/TaskProcessing/Db/Task.php @@ -98,9 +98,9 @@ class Task extends Entity { }, self::$fields)); } - public static function fromPublicTask(OCPTask $task): Task { + public static function fromPublicTask(OCPTask $task): self { /** @var Task $taskEntity */ - $taskEntity = Task::fromParams([ + $taskEntity = self::fromParams([ 'id' => $task->getId(), 'type' => $task->getTaskTypeId(), 'lastUpdated' => time(), diff --git a/lib/private/TaskProcessing/Manager.php b/lib/private/TaskProcessing/Manager.php index d4c99d5c29b..058437db388 100644 --- a/lib/private/TaskProcessing/Manager.php +++ b/lib/private/TaskProcessing/Manager.php @@ -385,6 +385,9 @@ class Manager implements IManager { try { /** @var IProvider $provider */ $provider = $this->serverContainer->get($class); + if (isset($providers[$provider->getId()])) { + $this->logger->warning('Task processing provider ' . $class . ' is using ID ' . $provider->getId() . ' which is already used by ' . $providers[$provider->getId()]::class); + } $providers[$provider->getId()] = $provider; } catch (\Throwable $e) { $this->logger->error('Failed to load task processing provider ' . $class, [ @@ -423,6 +426,9 @@ class Manager implements IManager { try { /** @var ITaskType $provider */ $taskType = $this->serverContainer->get($class); + if (isset($taskTypes[$taskType->getId()])) { + $this->logger->warning('Task processing task type ' . $class . ' is using ID ' . $taskType->getId() . ' which is already used by ' . $taskTypes[$taskType->getId()]::class); + } $taskTypes[$taskType->getId()] = $taskType; } catch (\Throwable $e) { $this->logger->error('Failed to load task processing task type ' . $class, [ diff --git a/lib/private/TaskProcessing/RemoveOldTasksBackgroundJob.php b/lib/private/TaskProcessing/RemoveOldTasksBackgroundJob.php index c68ead4e675..2619b649e61 100644 --- a/lib/private/TaskProcessing/RemoveOldTasksBackgroundJob.php +++ b/lib/private/TaskProcessing/RemoveOldTasksBackgroundJob.php @@ -40,7 +40,15 @@ class RemoveOldTasksBackgroundJob extends TimedJob { } try { $this->clearFilesOlderThan($this->appData->getFolder('text2image'), self::MAX_TASK_AGE_SECONDS); + } catch (NotFoundException $e) { + // noop + } + try { $this->clearFilesOlderThan($this->appData->getFolder('audio2text'), self::MAX_TASK_AGE_SECONDS); + } catch (NotFoundException $e) { + // noop + } + try { $this->clearFilesOlderThan($this->appData->getFolder('TaskProcessing'), self::MAX_TASK_AGE_SECONDS); } catch (NotFoundException $e) { // noop |