diff options
author | Marcel Klehr <mklehr@gmx.net> | 2024-05-03 12:23:59 +0200 |
---|---|---|
committer | Marcel Klehr <mklehr@gmx.net> | 2024-05-14 11:38:40 +0200 |
commit | b150d779f33ac2a417b5dcc5f451412f32552388 (patch) | |
tree | 28d6b7d043c0c5e8831c584f4db709ed41a1a314 | |
parent | c9ea5375d87a90a5c25a5858aed6fdcb1b035a9f (diff) | |
download | nextcloud-server-b150d779f33ac2a417b5dcc5f451412f32552388.tar.gz nextcloud-server-b150d779f33ac2a417b5dcc5f451412f32552388.zip |
refactor: rename getTaskType to getTaskTypeId
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
-rw-r--r-- | core/Controller/TaskProcessingApiController.php | 4 | ||||
-rw-r--r-- | lib/private/TaskProcessing/Db/Task.php | 2 | ||||
-rw-r--r-- | lib/private/TaskProcessing/Manager.php | 36 | ||||
-rw-r--r-- | lib/private/TaskProcessing/SynchronousBackgroundJob.php | 2 | ||||
-rw-r--r-- | lib/public/TaskProcessing/IProvider.php | 2 | ||||
-rw-r--r-- | lib/public/TaskProcessing/Task.php | 6 | ||||
-rw-r--r-- | tests/lib/TaskProcessing/TaskProcessingTest.php | 8 |
7 files changed, 30 insertions, 30 deletions
diff --git a/core/Controller/TaskProcessingApiController.php b/core/Controller/TaskProcessingApiController.php index cd8b9673871..d1084399b90 100644 --- a/core/Controller/TaskProcessingApiController.php +++ b/core/Controller/TaskProcessingApiController.php @@ -263,10 +263,10 @@ class TaskProcessingApiController extends \OCP\AppFramework\OCSController { private function extractFileIdsFromTask(Task $task) { $ids = []; $taskTypes = $this->taskProcessingManager->getAvailableTaskTypes(); - if (!isset($taskTypes[$task->getTaskType()])) { + if (!isset($taskTypes[$task->getTaskTypeId()])) { throw new \OCP\TaskProcessing\Exception\NotFoundException('Could not find task type'); } - $taskType = $taskTypes[$task->getTaskType()]; + $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)) { $ids[] = $task->getInput()[$key]; diff --git a/lib/private/TaskProcessing/Db/Task.php b/lib/private/TaskProcessing/Db/Task.php index 3712d0ac422..a506ffd86c9 100644 --- a/lib/private/TaskProcessing/Db/Task.php +++ b/lib/private/TaskProcessing/Db/Task.php @@ -102,7 +102,7 @@ class Task extends Entity { /** @var Task $taskEntity */ $taskEntity = Task::fromParams([ 'id' => $task->getId(), - 'type' => $task->getTaskType(), + 'type' => $task->getTaskTypeId(), 'lastUpdated' => time(), 'status' => $task->getStatus(), 'input' => json_encode($task->getInput(), JSON_THROW_ON_ERROR), diff --git a/lib/private/TaskProcessing/Manager.php b/lib/private/TaskProcessing/Manager.php index 793bcec6364..6582e6c1767 100644 --- a/lib/private/TaskProcessing/Manager.php +++ b/lib/private/TaskProcessing/Manager.php @@ -121,7 +121,7 @@ class Manager implements IManager { return $this->provider->getName(); } - public function getTaskType(): string { + public function getTaskTypeId(): string { return match ($this->provider->getTaskType()) { \OCP\TextProcessing\FreePromptTaskType::class => TextToText::ID, \OCP\TextProcessing\HeadlineTaskType::class => TextToTextHeadline::ID, @@ -240,7 +240,7 @@ class Manager implements IManager { return $this->provider->getName(); } - public function getTaskType(): string { + public function getTaskTypeId(): string { return TextToImage::ID; } @@ -327,7 +327,7 @@ class Manager implements IManager { return $this->provider->getName(); } - public function getTaskType(): string { + public function getTaskTypeId(): string { return AudioToText::ID; } @@ -451,7 +451,7 @@ class Manager implements IManager { private function _getPreferredProvider(string $taskType) { $providers = $this->getProviders(); foreach ($providers as $provider) { - if ($provider->getTaskType() === $taskType) { + if ($provider->getTaskTypeId() === $taskType) { return $provider; } } @@ -535,11 +535,11 @@ class Manager implements IManager { $availableTaskTypes = []; foreach ($providers as $provider) { - if (!isset($taskTypes[$provider->getTaskType()])) { + if (!isset($taskTypes[$provider->getTaskTypeId()])) { continue; } - $taskType = $taskTypes[$provider->getTaskType()]; - $availableTaskTypes[$provider->getTaskType()] = [ + $taskType = $taskTypes[$provider->getTaskTypeId()]; + $availableTaskTypes[$provider->getTaskTypeId()] = [ 'name' => $taskType->getName(), 'description' => $taskType->getDescription(), 'inputShape' => $taskType->getInputShape(), @@ -556,23 +556,23 @@ class Manager implements IManager { } public function canHandleTask(Task $task): bool { - return isset($this->getAvailableTaskTypes()[$task->getTaskType()]); + return isset($this->getAvailableTaskTypes()[$task->getTaskTypeId()]); } public function scheduleTask(Task $task): void { if (!$this->canHandleTask($task)) { - throw new PreConditionNotMetException('No task processing provider is installed that can handle this task type: ' . $task->getTaskType()); + throw new PreConditionNotMetException('No task processing provider is installed that can handle this task type: ' . $task->getTaskTypeId()); } $taskTypes = $this->getAvailableTaskTypes(); - $inputShape = $taskTypes[$task->getTaskType()]['inputShape']; - $optionalInputShape = $taskTypes[$task->getTaskType()]['optionalInputShape']; + $inputShape = $taskTypes[$task->getTaskTypeId()]['inputShape']; + $optionalInputShape = $taskTypes[$task->getTaskTypeId()]['optionalInputShape']; // validate input $this->validateInput($inputShape, $task->getInput()); $this->validateInput($optionalInputShape, $task->getInput(), true); // remove superfluous keys and set input $task->setInput($this->removeSuperfluousArrayKeys($task->getInput(), $inputShape, $optionalInputShape)); $task->setStatus(Task::STATUS_SCHEDULED); - $provider = $this->_getPreferredProvider($task->getTaskType()); + $provider = $this->_getPreferredProvider($task->getTaskTypeId()); // calculate expected completion time $completionExpectedAt = new \DateTime('now'); $completionExpectedAt->add(new \DateInterval('PT'.$provider->getExpectedRuntime().'S')); @@ -638,17 +638,17 @@ class Manager implements IManager { // TODO: Not sure if we should rather catch the exceptions of getTask here and fail silently $task = $this->getTask($id); if ($task->getStatus() === Task::STATUS_CANCELLED) { - $this->logger->info('A TaskProcessing ' . $task->getTaskType() . ' task with id ' . $id . ' finished but was cancelled in the mean time. Moving on without storing result.'); + $this->logger->info('A TaskProcessing ' . $task->getTaskTypeId() . ' task with id ' . $id . ' finished but was cancelled in the mean time. Moving on without storing result.'); return; } if ($error !== null) { $task->setStatus(Task::STATUS_FAILED); $task->setErrorMessage($error); - $this->logger->warning('A TaskProcessing ' . $task->getTaskType() . ' task with id ' . $id . ' failed with the following message: ' . $error); + $this->logger->warning('A TaskProcessing ' . $task->getTaskTypeId() . ' task with id ' . $id . ' failed with the following message: ' . $error); } elseif ($result !== null) { $taskTypes = $this->getAvailableTaskTypes(); - $outputShape = $taskTypes[$task->getTaskType()]['outputShape']; - $optionalOutputShape = $taskTypes[$task->getTaskType()]['optionalOutputShape']; + $outputShape = $taskTypes[$task->getTaskTypeId()]['outputShape']; + $optionalOutputShape = $taskTypes[$task->getTaskTypeId()]['optionalOutputShape']; try { // validate output $this->validateOutput($outputShape, $result); @@ -823,8 +823,8 @@ class Manager implements IManager { public function prepareInputData(Task $task): array { $taskTypes = $this->getAvailableTaskTypes(); - $inputShape = $taskTypes[$task->getTaskType()]['inputShape']; - $optionalInputShape = $taskTypes[$task->getTaskType()]['optionalInputShape']; + $inputShape = $taskTypes[$task->getTaskTypeId()]['inputShape']; + $optionalInputShape = $taskTypes[$task->getTaskTypeId()]['optionalInputShape']; $input = $task->getInput(); // validate input, again for good measure (should have been validated in scheduleTask) $this->validateInput($inputShape, $input); diff --git a/lib/private/TaskProcessing/SynchronousBackgroundJob.php b/lib/private/TaskProcessing/SynchronousBackgroundJob.php index ab85d469089..c7f4706c392 100644 --- a/lib/private/TaskProcessing/SynchronousBackgroundJob.php +++ b/lib/private/TaskProcessing/SynchronousBackgroundJob.php @@ -37,7 +37,7 @@ class SynchronousBackgroundJob extends QueuedJob { if (!$provider instanceof ISynchronousProvider) { continue; } - $taskType = $provider->getTaskType(); + $taskType = $provider->getTaskTypeId(); try { $task = $this->taskProcessingManager->getNextScheduledTask($taskType); } catch (NotFoundException $e) { diff --git a/lib/public/TaskProcessing/IProvider.php b/lib/public/TaskProcessing/IProvider.php index 5768294fd96..dd20fdd8a70 100644 --- a/lib/public/TaskProcessing/IProvider.php +++ b/lib/public/TaskProcessing/IProvider.php @@ -51,7 +51,7 @@ interface IProvider { * @since 30.0.0 * @return string */ - public function getTaskType(): string; + public function getTaskTypeId(): string; /** * @return int The expected average runtime of a task in seconds diff --git a/lib/public/TaskProcessing/Task.php b/lib/public/TaskProcessing/Task.php index 58c420a9992..4bddd06162f 100644 --- a/lib/public/TaskProcessing/Task.php +++ b/lib/public/TaskProcessing/Task.php @@ -82,7 +82,7 @@ final class Task implements \JsonSerializable { * @since 30.0.0 */ final public function __construct( - protected readonly string $taskType, + protected readonly string $taskTypeId, protected array $input, protected readonly string $appId, protected readonly ?string $userId, @@ -93,8 +93,8 @@ final class Task implements \JsonSerializable { /** * @since 30.0.0 */ - final public function getTaskType(): string { - return $this->taskType; + final public function getTaskTypeId(): string { + return $this->taskTypeId; } /** diff --git a/tests/lib/TaskProcessing/TaskProcessingTest.php b/tests/lib/TaskProcessing/TaskProcessingTest.php index ddf64f23173..b9d402bbde8 100644 --- a/tests/lib/TaskProcessing/TaskProcessingTest.php +++ b/tests/lib/TaskProcessing/TaskProcessingTest.php @@ -80,7 +80,7 @@ class AsyncProvider implements IProvider { return self::class; } - public function getTaskType(): string { + public function getTaskTypeId(): string { return AudioToImage::ID; } @@ -110,7 +110,7 @@ class SuccessfulSyncProvider implements IProvider, ISynchronousProvider { return self::class; } - public function getTaskType(): string { + public function getTaskTypeId(): string { return TextToText::ID; } @@ -145,7 +145,7 @@ class FailingSyncProvider implements IProvider, ISynchronousProvider { return self::class; } - public function getTaskType(): string { + public function getTaskTypeId(): string { return TextToText::ID; } @@ -179,7 +179,7 @@ class BrokenSyncProvider implements IProvider, ISynchronousProvider { return self::class; } - public function getTaskType(): string { + public function getTaskTypeId(): string { return TextToText::ID; } |