From 3dcedb7900534091c73f9344780a02653e131c14 Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Tue, 24 Oct 2023 14:41:24 +0200 Subject: enh(TextProcessing): Allow providers and task types to declare a dynamic ID instead of using className this allows AppAPI to register anonymous classes as TextProcessing providers and task types Signed-off-by: Marcel Klehr --- lib/public/TextProcessing/IProvider.php | 2 +- lib/public/TextProcessing/IProviderWithId.php | 39 +++++++++++++++++++++++++++ lib/public/TextProcessing/ITaskTypeWithId.php | 37 +++++++++++++++++++++++++ lib/public/TextProcessing/Task.php | 4 +-- 4 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 lib/public/TextProcessing/IProviderWithId.php create mode 100644 lib/public/TextProcessing/ITaskTypeWithId.php (limited to 'lib/public/TextProcessing') diff --git a/lib/public/TextProcessing/IProvider.php b/lib/public/TextProcessing/IProvider.php index 6132e60b493..01c17f4bfbf 100644 --- a/lib/public/TextProcessing/IProvider.php +++ b/lib/public/TextProcessing/IProvider.php @@ -56,7 +56,7 @@ interface IProvider { * provider handles * * @since 27.1.0 - * @return class-string + * @return class-string|string */ public function getTaskType(): string; } diff --git a/lib/public/TextProcessing/IProviderWithId.php b/lib/public/TextProcessing/IProviderWithId.php new file mode 100644 index 00000000000..3d86b50b2c8 --- /dev/null +++ b/lib/public/TextProcessing/IProviderWithId.php @@ -0,0 +1,39 @@ + + * + * @author Marcel Klehr + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + + +namespace OCP\TextProcessing; + +/** + * @since 28.0.0 + */ +interface IProviderWithId extends IProvider { + + /** + * The id of this provider + * @since 28.0.0 + */ + public function getId(): string; +} diff --git a/lib/public/TextProcessing/ITaskTypeWithId.php b/lib/public/TextProcessing/ITaskTypeWithId.php new file mode 100644 index 00000000000..b86b831f266 --- /dev/null +++ b/lib/public/TextProcessing/ITaskTypeWithId.php @@ -0,0 +1,37 @@ + + * + * @author Marcel Klehr + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +namespace OCP\TextProcessing; + +/** + * @since 28.0.0 + */ +interface ITaskTypeWithId { + /** + * The id of this provider + * @since 28.0.0 + */ + public function getId(): string; +} diff --git a/lib/public/TextProcessing/Task.php b/lib/public/TextProcessing/Task.php index 446e414cb04..52a7637bd7c 100644 --- a/lib/public/TextProcessing/Task.php +++ b/lib/public/TextProcessing/Task.php @@ -29,8 +29,8 @@ namespace OCP\TextProcessing; * This is a text processing task * @since 27.1.0 * @psalm-template T of ITaskType - * @psalm-template S as class-string - * @psalm-template P as IProvider + * @psalm-template S as class-string | string + * @psalm-template P as IProvider | IProvider */ final class Task implements \JsonSerializable { protected ?int $id = null; -- cgit v1.2.3 From be0a0166e8879a88677adb105f8f41a2dcfa4f13 Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Tue, 24 Oct 2023 15:34:51 +0200 Subject: fix(TextProcessing): fix psalm typing Signed-off-by: Marcel Klehr --- lib/public/TextProcessing/IManager.php | 2 +- lib/public/TextProcessing/IProviderWithId.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/public/TextProcessing') diff --git a/lib/public/TextProcessing/IManager.php b/lib/public/TextProcessing/IManager.php index dec0baba4bb..4604dc4d663 100644 --- a/lib/public/TextProcessing/IManager.php +++ b/lib/public/TextProcessing/IManager.php @@ -48,7 +48,7 @@ interface IManager { public function getProviders(): array; /** - * @return class-string[] + * @return string[] * @since 27.1.0 */ public function getAvailableTaskTypes(): array; diff --git a/lib/public/TextProcessing/IProviderWithId.php b/lib/public/TextProcessing/IProviderWithId.php index 3d86b50b2c8..6723168988e 100644 --- a/lib/public/TextProcessing/IProviderWithId.php +++ b/lib/public/TextProcessing/IProviderWithId.php @@ -23,11 +23,11 @@ declare(strict_types=1); * along with this program. If not, see . */ - namespace OCP\TextProcessing; /** * @since 28.0.0 + * @extends IProvider */ interface IProviderWithId extends IProvider { -- cgit v1.2.3 From 181f819e417a1818f37200f9071fa632c82a0fc2 Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Fri, 3 Nov 2023 16:22:54 +0100 Subject: enh(TextProcessing): Add IProvider2 - allow providers to obtain current task's userId - allow providers to expose average task runtime Signed-off-by: Marcel Klehr --- core/Controller/TextProcessingApiController.php | 11 +++- core/Migrations/Version28000Date20231103104802.php | 60 +++++++++++++++++++ core/ResponseDefinitions.php | 1 + lib/private/TextProcessing/Db/Task.php | 10 +++- lib/private/TextProcessing/Manager.php | 69 +++++++++++++++++----- lib/public/TextProcessing/IManager.php | 16 +++++ lib/public/TextProcessing/IProvider2.php | 48 +++++++++++++++ lib/public/TextProcessing/Task.php | 19 +++++- 8 files changed, 213 insertions(+), 21 deletions(-) create mode 100644 core/Migrations/Version28000Date20231103104802.php create mode 100644 lib/public/TextProcessing/IProvider2.php (limited to 'lib/public/TextProcessing') diff --git a/core/Controller/TextProcessingApiController.php b/core/Controller/TextProcessingApiController.php index 8b5175f0e5c..6b975a7ed61 100644 --- a/core/Controller/TextProcessingApiController.php +++ b/core/Controller/TextProcessingApiController.php @@ -35,6 +35,7 @@ use OCP\AppFramework\Http\Attribute\PublicPage; use OCP\AppFramework\Http\Attribute\UserRateLimit; use OCP\AppFramework\Http\DataResponse; use OCP\Common\Exception\NotFoundException; +use OCP\DB\Exception; use OCP\IL10N; use OCP\IRequest; use OCP\TextProcessing\ITaskType; @@ -102,7 +103,7 @@ class TextProcessingApiController extends \OCP\AppFramework\OCSController { * @param string $appId ID of the app that will execute the task * @param string $identifier An arbitrary identifier for the task * - * @return DataResponse|DataResponse + * @return DataResponse|DataResponse * * 200: Task scheduled successfully * 400: Scheduling task is not possible @@ -118,7 +119,11 @@ class TextProcessingApiController extends \OCP\AppFramework\OCSController { return new DataResponse(['message' => $this->l->t('Requested task type does not exist')], Http::STATUS_BAD_REQUEST); } try { - $this->textProcessingManager->scheduleTask($task); + try { + $this->textProcessingManager->runOrScheduleTask($task); + } catch(\RuntimeException) { + // noop, because the task object has the failure status set already, we just return the task json + } $json = $task->jsonSerialize(); @@ -127,6 +132,8 @@ class TextProcessingApiController extends \OCP\AppFramework\OCSController { ]); } catch (PreConditionNotMetException) { return new DataResponse(['message' => $this->l->t('Necessary language model provider is not available')], Http::STATUS_PRECONDITION_FAILED); + } catch (Exception) { + return new DataResponse(['message' => 'Internal server error'], Http::STATUS_INTERNAL_SERVER_ERROR); } } diff --git a/core/Migrations/Version28000Date20231103104802.php b/core/Migrations/Version28000Date20231103104802.php new file mode 100644 index 00000000000..69dddbccee9 --- /dev/null +++ b/core/Migrations/Version28000Date20231103104802.php @@ -0,0 +1,60 @@ + + * + * @author Marcel Klehr + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +namespace OC\Core\Migrations; + +use Closure; +use OCP\DB\ISchemaWrapper; +use OCP\DB\Types; +use OCP\Migration\IOutput; +use OCP\Migration\SimpleMigrationStep; + +/** + * Introduce completion_expected_at column in textprocessing_tasks table + */ +class Version28000Date20231103104802 extends SimpleMigrationStep { + /** + * @param IOutput $output + * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` + * @param array $options + * @return null|ISchemaWrapper + */ + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper { + /** @var ISchemaWrapper $schema */ + $schema = $schemaClosure(); + if ($schema->hasTable('textprocessing_tasks')) { + $table = $schema->getTable('textprocessing_tasks'); + + $table->addColumn('completion_expected_at', Types::DATETIME, [ + 'notnull' => false, + ]); + + return $schema; + } + + return null; + } +} diff --git a/core/ResponseDefinitions.php b/core/ResponseDefinitions.php index ca3f117051c..6e51b7bd9b7 100644 --- a/core/ResponseDefinitions.php +++ b/core/ResponseDefinitions.php @@ -143,6 +143,7 @@ namespace OCA\Core; * input: string, * output: ?string, * identifier: string, + * completionExpectedAt: ?int * } * * @psalm-type CoreTextToImageTask = array{ diff --git a/lib/private/TextProcessing/Db/Task.php b/lib/private/TextProcessing/Db/Task.php index 9c6f16d11ae..5f362d429f3 100644 --- a/lib/private/TextProcessing/Db/Task.php +++ b/lib/private/TextProcessing/Db/Task.php @@ -45,6 +45,8 @@ use OCP\TextProcessing\Task as OCPTask; * @method string getAppId() * @method setIdentifier(string $identifier) * @method string getIdentifier() + * @method setCompletionExpectedAt(null|\DateTime $completionExpectedAt) + * @method null|\DateTime getCompletionExpectedAt() */ class Task extends Entity { protected $lastUpdated; @@ -55,16 +57,17 @@ class Task extends Entity { protected $userId; protected $appId; protected $identifier; + protected $completionExpectedAt; /** * @var string[] */ - public static array $columns = ['id', 'last_updated', 'type', 'input', 'output', 'status', 'user_id', 'app_id', 'identifier']; + public static array $columns = ['id', 'last_updated', 'type', 'input', 'output', 'status', 'user_id', 'app_id', 'identifier', 'completion_expected_at']; /** * @var string[] */ - public static array $fields = ['id', 'lastUpdated', 'type', 'input', 'output', 'status', 'userId', 'appId', 'identifier']; + public static array $fields = ['id', 'lastUpdated', 'type', 'input', 'output', 'status', 'userId', 'appId', 'identifier', 'completionExpectedAt']; public function __construct() { @@ -78,6 +81,7 @@ class Task extends Entity { $this->addType('userId', 'string'); $this->addType('appId', 'string'); $this->addType('identifier', 'string'); + $this->addType('completionExpectedAt', 'datetime'); } public function toRow(): array { @@ -98,6 +102,7 @@ class Task extends Entity { 'userId' => $task->getUserId(), 'appId' => $task->getAppId(), 'identifier' => $task->getIdentifier(), + 'completionExpectedAt' => $task->getCompletionExpectedAt(), ]); return $task; } @@ -107,6 +112,7 @@ class Task extends Entity { $task->setId($this->getId()); $task->setStatus($this->getStatus()); $task->setOutput($this->getOutput()); + $task->setCompletionExpectedAt($this->getCompletionExpectedAt()); return $task; } } diff --git a/lib/private/TextProcessing/Manager.php b/lib/private/TextProcessing/Manager.php index b9cb06c298e..bee70b53a33 100644 --- a/lib/private/TextProcessing/Manager.php +++ b/lib/private/TextProcessing/Manager.php @@ -28,6 +28,7 @@ namespace OC\TextProcessing; use OC\AppFramework\Bootstrap\Coordinator; use OC\TextProcessing\Db\Task as DbTask; use OCP\IConfig; +use OCP\TextProcessing\IProvider2; use OCP\TextProcessing\Task; use OCP\TextProcessing\Task as OCPTask; use OC\TextProcessing\Db\TaskMapper; @@ -114,19 +115,7 @@ class Manager implements IManager { if (!$this->canHandleTask($task)) { throw new PreConditionNotMetException('No text processing provider is installed that can handle this task'); } - $providers = $this->getProviders(); - $json = $this->config->getAppValue('core', 'ai.textprocessing_provider_preferences', ''); - if ($json !== '') { - $preferences = json_decode($json, true); - if (isset($preferences[$task->getType()])) { - // If a preference for this task type is set, move the preferred provider to the start - $provider = current(array_filter($providers, fn ($provider) => $provider::class === $preferences[$task->getType()])); - if ($provider !== false) { - $providers = array_filter($providers, fn ($p) => $p !== $provider); - array_unshift($providers, $provider); - } - } - } + $providers = $this->getPreferredProviders($task); foreach ($providers as $provider) { if (!$task->canUseProvider($provider)) { @@ -134,6 +123,11 @@ class Manager implements IManager { } try { $task->setStatus(OCPTask::STATUS_RUNNING); + if ($provider instanceof IProvider2) { + $completionExpectedAt = new \DateTime('now'); + $completionExpectedAt->add(new \DateInterval('PT'.$provider->getExpectedRuntime().'S')); + $task->setCompletionExpectedAt($completionExpectedAt); + } if ($task->getId() === null) { $taskEntity = $this->taskMapper->insert(DbTask::fromPublicTask($task)); $task->setId($taskEntity->getId()); @@ -158,18 +152,25 @@ class Manager implements IManager { } } + $task->setStatus(OCPTask::STATUS_FAILED); + $this->taskMapper->update(DbTask::fromPublicTask($task)); throw new RuntimeException('Could not run task'); } /** * @inheritDoc - * @throws Exception */ public function scheduleTask(OCPTask $task): void { if (!$this->canHandleTask($task)) { throw new PreConditionNotMetException('No LanguageModel provider is installed that can handle this task'); } $task->setStatus(OCPTask::STATUS_SCHEDULED); + [$provider, ] = $this->getPreferredProviders($task); + if ($provider instanceof IProvider2) { + $completionExpectedAt = new \DateTime('now'); + $completionExpectedAt->add(new \DateInterval('PT'.$provider->getExpectedRuntime().'S')); + $task->setCompletionExpectedAt($completionExpectedAt); + } $taskEntity = DbTask::fromPublicTask($task); $this->taskMapper->insert($taskEntity); $task->setId($taskEntity->getId()); @@ -178,6 +179,25 @@ class Manager implements IManager { ]); } + /** + * @inheritDoc + */ + public function runOrScheduleTask(OCPTask $task) : bool { + if (!$this->canHandleTask($task)) { + throw new PreConditionNotMetException('No LanguageModel provider is installed that can handle this task'); + } + [$provider,] = $this->getPreferredProviders($task); + $maxExecutionTime = (int) ini_get('max_execution_time'); + // Offload the task to a background job if the expected runtime of the likely provider is longer than 80% of our max execution time + // or if the provider doesn't provide a getExpectedRuntime() method + if (!$provider instanceof IProvider2 || $provider->getExpectedRuntime() > $maxExecutionTime * 0.8) { + $this->scheduleTask($task); + return false; + } + $this->runTask($task); + return true; + } + /** * @inheritDoc */ @@ -253,4 +273,25 @@ class Manager implements IManager { throw new RuntimeException('Failure while trying to find tasks by appId and identifier: ' . $e->getMessage(), 0, $e); } } + + /** + * @param OCPTask $task + * @return IProvider[] + */ + public function getPreferredProviders(OCPTask $task): array { + $providers = $this->getProviders(); + $json = $this->config->getAppValue('core', 'ai.textprocessing_provider_preferences', ''); + if ($json !== '') { + $preferences = json_decode($json, true); + if (isset($preferences[$task->getType()])) { + // If a preference for this task type is set, move the preferred provider to the start + $provider = current(array_filter($providers, fn ($provider) => $provider::class === $preferences[$task->getType()])); + if ($provider !== false) { + $providers = array_filter($providers, fn ($p) => $p !== $provider); + array_unshift($providers, $provider); + } + } + } + return $providers; + } } diff --git a/lib/public/TextProcessing/IManager.php b/lib/public/TextProcessing/IManager.php index dec0baba4bb..aae686e318c 100644 --- a/lib/public/TextProcessing/IManager.php +++ b/lib/public/TextProcessing/IManager.php @@ -27,6 +27,7 @@ declare(strict_types=1); namespace OCP\TextProcessing; use OCP\Common\Exception\NotFoundException; +use OCP\DB\Exception; use OCP\PreConditionNotMetException; use RuntimeException; @@ -68,10 +69,25 @@ interface IManager { * * @param Task $task The task to schedule * @throws PreConditionNotMetException If no or not the requested provider was registered but this method was still called + * @throws Exception storing the task in the database failed * @since 27.1.0 */ public function scheduleTask(Task $task) : void; + /** + * If the designated provider for the passed task provides an expected average runtime, we check if the runtime fits into the + * max execution time of this php process and run it synchronously if it does, if it doesn't fit (or the provider doesn't provide that information) + * execution is deferred to a background job + * + * @param Task $task The task to schedule + * @returns bool A boolean indicating whether the task was run synchronously (`true`) or offloaded to a background job (`false`) + * @throws PreConditionNotMetException If no or not the requested provider was registered but this method was still called + * @throws RuntimeException If running the task failed + * @throws Exception storing the task in the database failed + * @since 28.0.0 + */ + public function runOrScheduleTask(Task $task): bool; + /** * Delete a task that has been scheduled before * diff --git a/lib/public/TextProcessing/IProvider2.php b/lib/public/TextProcessing/IProvider2.php new file mode 100644 index 00000000000..74e6a47fed5 --- /dev/null +++ b/lib/public/TextProcessing/IProvider2.php @@ -0,0 +1,48 @@ + + * + * @author Marcel Klehr + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + + +namespace OCP\TextProcessing; + +/** + * This interface supersedes IProvider. It allows the system to learn + * the provider's expected runtime and lets the provider know which user is running a task + * @since 28.0.0 + * @template T of ITaskType + * @template-extends IProvider + */ +interface IProvider2 extends IProvider { + /** + * @param ?string $userId the current user's id + * @since 28.0.0 + */ + public function setUserId(?string $userId): string; + + /** + * @return int The expected average runtime of a task in seconds + * @since 28.0.0 + */ + public function getExpectedRuntime(): int; +} diff --git a/lib/public/TextProcessing/Task.php b/lib/public/TextProcessing/Task.php index 446e414cb04..16850348358 100644 --- a/lib/public/TextProcessing/Task.php +++ b/lib/public/TextProcessing/Task.php @@ -35,6 +35,7 @@ namespace OCP\TextProcessing; final class Task implements \JsonSerializable { protected ?int $id = null; protected ?string $output = null; + private ?\DateTime $completionExpectedAt = null; /** * @since 27.1.0 @@ -92,12 +93,15 @@ final class Task implements \JsonSerializable { /** * @psalm-param P $provider - * @param IProvider $provider + * @param IProvider|IProvider2 $provider * @return string * @since 27.1.0 */ - public function visitProvider(IProvider $provider): string { + public function visitProvider(IProvider|IProvider2 $provider): string { if ($this->canUseProvider($provider)) { + if ($provider instanceof IProvider2) { + $provider->setUserId($this->getUserId()); + } return $provider->process($this->getInput()); } else { throw new \RuntimeException('Task of type ' . $this->getType() . ' cannot visit provider with task type ' . $provider->getTaskType()); @@ -203,7 +207,7 @@ final class Task implements \JsonSerializable { } /** - * @psalm-return array{id: ?int, type: S, status: 0|1|2|3|4, userId: ?string, appId: string, input: string, output: ?string, identifier: string} + * @psalm-return array{id: ?int, type: S, status: 0|1|2|3|4, userId: ?string, appId: string, input: string, output: ?string, identifier: string, completionExpectedAt: ?int} * @since 27.1.0 */ public function jsonSerialize(): array { @@ -216,6 +220,15 @@ final class Task implements \JsonSerializable { 'input' => $this->getInput(), 'output' => $this->getOutput(), 'identifier' => $this->getIdentifier(), + 'completionExpectedAt' => $this->getCompletionExpectedAt()?->getTimestamp(), ]; } + +final public function setCompletionExpectedAt(\DateTime $completionExpectedAt): void { + $this->completionExpectedAt = $completionExpectedAt; +} + +final public function getCompletionExpectedAt(): ?\DateTime { + return $this->completionExpectedAt; +} } -- cgit v1.2.3 From d11b9cbd7993042fcf9ba49d5c8ef14bf928d901 Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Mon, 6 Nov 2023 12:50:16 +0100 Subject: fix(TextProcessing/Manager): Throw TaskFailureException upon failure Signed-off-by: Marcel Klehr --- core/Controller/TextProcessingApiController.php | 3 ++- lib/private/TextProcessing/Manager.php | 10 +++------- lib/public/TextProcessing/Exception/TaskFailureException.php | 7 +++++++ lib/public/TextProcessing/IManager.php | 5 +++-- 4 files changed, 15 insertions(+), 10 deletions(-) create mode 100644 lib/public/TextProcessing/Exception/TaskFailureException.php (limited to 'lib/public/TextProcessing') diff --git a/core/Controller/TextProcessingApiController.php b/core/Controller/TextProcessingApiController.php index 6b975a7ed61..a6b85fd46ae 100644 --- a/core/Controller/TextProcessingApiController.php +++ b/core/Controller/TextProcessingApiController.php @@ -38,6 +38,7 @@ use OCP\Common\Exception\NotFoundException; use OCP\DB\Exception; use OCP\IL10N; use OCP\IRequest; +use OCP\TextProcessing\Exception\TaskFailureException; use OCP\TextProcessing\ITaskType; use OCP\TextProcessing\Task; use OCP\TextProcessing\IManager; @@ -121,7 +122,7 @@ class TextProcessingApiController extends \OCP\AppFramework\OCSController { try { try { $this->textProcessingManager->runOrScheduleTask($task); - } catch(\RuntimeException) { + } catch(TaskFailureException) { // noop, because the task object has the failure status set already, we just return the task json } diff --git a/lib/private/TextProcessing/Manager.php b/lib/private/TextProcessing/Manager.php index bee70b53a33..439ffde4521 100644 --- a/lib/private/TextProcessing/Manager.php +++ b/lib/private/TextProcessing/Manager.php @@ -28,6 +28,7 @@ namespace OC\TextProcessing; use OC\AppFramework\Bootstrap\Coordinator; use OC\TextProcessing\Db\Task as DbTask; use OCP\IConfig; +use OCP\TextProcessing\Exception\TaskFailureException; use OCP\TextProcessing\IProvider2; use OCP\TextProcessing\Task; use OCP\TextProcessing\Task as OCPTask; @@ -139,22 +140,17 @@ class Manager implements IManager { $task->setStatus(OCPTask::STATUS_SUCCESSFUL); $this->taskMapper->update(DbTask::fromPublicTask($task)); return $output; - } catch (\RuntimeException $e) { - $this->logger->info('LanguageModel call using provider ' . $provider->getName() . ' failed', ['exception' => $e]); - $task->setStatus(OCPTask::STATUS_FAILED); - $this->taskMapper->update(DbTask::fromPublicTask($task)); - throw $e; } catch (\Throwable $e) { $this->logger->info('LanguageModel call using provider ' . $provider->getName() . ' failed', ['exception' => $e]); $task->setStatus(OCPTask::STATUS_FAILED); $this->taskMapper->update(DbTask::fromPublicTask($task)); - throw new RuntimeException('LanguageModel call using provider ' . $provider->getName() . ' failed: ' . $e->getMessage(), 0, $e); + throw new TaskFailureException('LanguageModel call using provider ' . $provider->getName() . ' failed: ' . $e->getMessage(), 0, $e); } } $task->setStatus(OCPTask::STATUS_FAILED); $this->taskMapper->update(DbTask::fromPublicTask($task)); - throw new RuntimeException('Could not run task'); + throw new TaskFailureException('Could not run task'); } /** diff --git a/lib/public/TextProcessing/Exception/TaskFailureException.php b/lib/public/TextProcessing/Exception/TaskFailureException.php new file mode 100644 index 00000000000..5f7b308757b --- /dev/null +++ b/lib/public/TextProcessing/Exception/TaskFailureException.php @@ -0,0 +1,7 @@ + Date: Mon, 6 Nov 2023 14:53:20 +0100 Subject: fix: psalm issues and coding style Signed-off-by: Marcel Klehr --- .../Exception/TaskFailureException.php | 5 ++++- lib/public/TextProcessing/Task.php | 21 +++++++++++++++------ 2 files changed, 19 insertions(+), 7 deletions(-) (limited to 'lib/public/TextProcessing') diff --git a/lib/public/TextProcessing/Exception/TaskFailureException.php b/lib/public/TextProcessing/Exception/TaskFailureException.php index 5f7b308757b..300864711e7 100644 --- a/lib/public/TextProcessing/Exception/TaskFailureException.php +++ b/lib/public/TextProcessing/Exception/TaskFailureException.php @@ -2,6 +2,9 @@ namespace OCP\TextProcessing\Exception; +/** + * Exception thrown when a task failed + * @since 28.0.0 + */ class TaskFailureException extends \RuntimeException { - } diff --git a/lib/public/TextProcessing/Task.php b/lib/public/TextProcessing/Task.php index 16850348358..f6b3a1a6a42 100644 --- a/lib/public/TextProcessing/Task.php +++ b/lib/public/TextProcessing/Task.php @@ -224,11 +224,20 @@ final class Task implements \JsonSerializable { ]; } -final public function setCompletionExpectedAt(\DateTime $completionExpectedAt): void { - $this->completionExpectedAt = $completionExpectedAt; -} + /** + * @param null|\DateTime $completionExpectedAt + * @return void + * @since 28.0.0 + */ + final public function setCompletionExpectedAt(?\DateTime $completionExpectedAt): void { + $this->completionExpectedAt = $completionExpectedAt; + } -final public function getCompletionExpectedAt(): ?\DateTime { - return $this->completionExpectedAt; -} + /** + * @return \DateTime|null + * @since 28.0.0 + */ + final public function getCompletionExpectedAt(): ?\DateTime { + return $this->completionExpectedAt; + } } -- cgit v1.2.3 From 17e7b6c7110e11c977852da91d62cab12cde0b49 Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Tue, 7 Nov 2023 12:02:03 +0100 Subject: fix: split IProvider2 into two more verbose interfaces Signed-off-by: Marcel Klehr --- lib/composer/composer/autoload_classmap.php | 4 ++ lib/composer/composer/autoload_static.php | 4 ++ lib/private/TextProcessing/Manager.php | 8 ++-- lib/public/TextProcessing/IProvider2.php | 48 ---------------------- .../IProviderWithExpectedRuntime.php | 42 +++++++++++++++++++ lib/public/TextProcessing/IProviderWithUserId.php | 41 ++++++++++++++++++ lib/public/TextProcessing/Task.php | 6 +-- 7 files changed, 98 insertions(+), 55 deletions(-) delete mode 100644 lib/public/TextProcessing/IProvider2.php create mode 100644 lib/public/TextProcessing/IProviderWithExpectedRuntime.php create mode 100644 lib/public/TextProcessing/IProviderWithUserId.php (limited to 'lib/public/TextProcessing') diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index b2d0b225574..3367077d833 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -666,10 +666,13 @@ return array( 'OCP\\TextProcessing\\Events\\AbstractTextProcessingEvent' => $baseDir . '/lib/public/TextProcessing/Events/AbstractTextProcessingEvent.php', 'OCP\\TextProcessing\\Events\\TaskFailedEvent' => $baseDir . '/lib/public/TextProcessing/Events/TaskFailedEvent.php', 'OCP\\TextProcessing\\Events\\TaskSuccessfulEvent' => $baseDir . '/lib/public/TextProcessing/Events/TaskSuccessfulEvent.php', + 'OCP\\TextProcessing\\Exception\\TaskFailureException' => $baseDir . '/lib/public/TextProcessing/Exception/TaskFailureException.php', 'OCP\\TextProcessing\\FreePromptTaskType' => $baseDir . '/lib/public/TextProcessing/FreePromptTaskType.php', 'OCP\\TextProcessing\\HeadlineTaskType' => $baseDir . '/lib/public/TextProcessing/HeadlineTaskType.php', 'OCP\\TextProcessing\\IManager' => $baseDir . '/lib/public/TextProcessing/IManager.php', 'OCP\\TextProcessing\\IProvider' => $baseDir . '/lib/public/TextProcessing/IProvider.php', + 'OCP\\TextProcessing\\IProviderWithExpectedRuntime' => $baseDir . '/lib/public/TextProcessing/IProviderWithExpectedRuntime.php', + 'OCP\\TextProcessing\\IProviderWithUserId' => $baseDir . '/lib/public/TextProcessing/IProviderWithUserId.php', 'OCP\\TextProcessing\\ITaskType' => $baseDir . '/lib/public/TextProcessing/ITaskType.php', 'OCP\\TextProcessing\\SummaryTaskType' => $baseDir . '/lib/public/TextProcessing/SummaryTaskType.php', 'OCP\\TextProcessing\\Task' => $baseDir . '/lib/public/TextProcessing/Task.php', @@ -1196,6 +1199,7 @@ return array( 'OC\\Core\\Migrations\\Version28000Date20230728104802' => $baseDir . '/core/Migrations/Version28000Date20230728104802.php', 'OC\\Core\\Migrations\\Version28000Date20230803221055' => $baseDir . '/core/Migrations/Version28000Date20230803221055.php', 'OC\\Core\\Migrations\\Version28000Date20230906104802' => $baseDir . '/core/Migrations/Version28000Date20230906104802.php', + 'OC\\Core\\Migrations\\Version28000Date20231103104802' => $baseDir . '/core/Migrations/Version28000Date20231103104802.php', 'OC\\Core\\Notification\\CoreNotifier' => $baseDir . '/core/Notification/CoreNotifier.php', 'OC\\Core\\Service\\LoginFlowV2Service' => $baseDir . '/core/Service/LoginFlowV2Service.php', 'OC\\DB\\Adapter' => $baseDir . '/lib/private/DB/Adapter.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 7e73255b29b..0f7e2de64ef 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -699,10 +699,13 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OCP\\TextProcessing\\Events\\AbstractTextProcessingEvent' => __DIR__ . '/../../..' . '/lib/public/TextProcessing/Events/AbstractTextProcessingEvent.php', 'OCP\\TextProcessing\\Events\\TaskFailedEvent' => __DIR__ . '/../../..' . '/lib/public/TextProcessing/Events/TaskFailedEvent.php', 'OCP\\TextProcessing\\Events\\TaskSuccessfulEvent' => __DIR__ . '/../../..' . '/lib/public/TextProcessing/Events/TaskSuccessfulEvent.php', + 'OCP\\TextProcessing\\Exception\\TaskFailureException' => __DIR__ . '/../../..' . '/lib/public/TextProcessing/Exception/TaskFailureException.php', 'OCP\\TextProcessing\\FreePromptTaskType' => __DIR__ . '/../../..' . '/lib/public/TextProcessing/FreePromptTaskType.php', 'OCP\\TextProcessing\\HeadlineTaskType' => __DIR__ . '/../../..' . '/lib/public/TextProcessing/HeadlineTaskType.php', 'OCP\\TextProcessing\\IManager' => __DIR__ . '/../../..' . '/lib/public/TextProcessing/IManager.php', 'OCP\\TextProcessing\\IProvider' => __DIR__ . '/../../..' . '/lib/public/TextProcessing/IProvider.php', + 'OCP\\TextProcessing\\IProviderWithExpectedRuntime' => __DIR__ . '/../../..' . '/lib/public/TextProcessing/IProviderWithExpectedRuntime.php', + 'OCP\\TextProcessing\\IProviderWithUserId' => __DIR__ . '/../../..' . '/lib/public/TextProcessing/IProviderWithUserId.php', 'OCP\\TextProcessing\\ITaskType' => __DIR__ . '/../../..' . '/lib/public/TextProcessing/ITaskType.php', 'OCP\\TextProcessing\\SummaryTaskType' => __DIR__ . '/../../..' . '/lib/public/TextProcessing/SummaryTaskType.php', 'OCP\\TextProcessing\\Task' => __DIR__ . '/../../..' . '/lib/public/TextProcessing/Task.php', @@ -1229,6 +1232,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OC\\Core\\Migrations\\Version28000Date20230728104802' => __DIR__ . '/../../..' . '/core/Migrations/Version28000Date20230728104802.php', 'OC\\Core\\Migrations\\Version28000Date20230803221055' => __DIR__ . '/../../..' . '/core/Migrations/Version28000Date20230803221055.php', 'OC\\Core\\Migrations\\Version28000Date20230906104802' => __DIR__ . '/../../..' . '/core/Migrations/Version28000Date20230906104802.php', + 'OC\\Core\\Migrations\\Version28000Date20231103104802' => __DIR__ . '/../../..' . '/core/Migrations/Version28000Date20231103104802.php', 'OC\\Core\\Notification\\CoreNotifier' => __DIR__ . '/../../..' . '/core/Notification/CoreNotifier.php', 'OC\\Core\\Service\\LoginFlowV2Service' => __DIR__ . '/../../..' . '/core/Service/LoginFlowV2Service.php', 'OC\\DB\\Adapter' => __DIR__ . '/../../..' . '/lib/private/DB/Adapter.php', diff --git a/lib/private/TextProcessing/Manager.php b/lib/private/TextProcessing/Manager.php index ee4fc70a06a..d1225b0f12f 100644 --- a/lib/private/TextProcessing/Manager.php +++ b/lib/private/TextProcessing/Manager.php @@ -29,7 +29,7 @@ use OC\AppFramework\Bootstrap\Coordinator; use OC\TextProcessing\Db\Task as DbTask; use OCP\IConfig; use OCP\TextProcessing\Exception\TaskFailureException; -use OCP\TextProcessing\IProvider2; +use OCP\TextProcessing\IProviderWithExpectedRuntime; use OCP\TextProcessing\Task; use OCP\TextProcessing\Task as OCPTask; use OC\TextProcessing\Db\TaskMapper; @@ -121,7 +121,7 @@ class Manager implements IManager { foreach ($providers as $provider) { try { $task->setStatus(OCPTask::STATUS_RUNNING); - if ($provider instanceof IProvider2) { + if ($provider instanceof IProviderWithExpectedRuntime) { $completionExpectedAt = new \DateTime('now'); $completionExpectedAt->add(new \DateInterval('PT'.$provider->getExpectedRuntime().'S')); $task->setCompletionExpectedAt($completionExpectedAt); @@ -159,7 +159,7 @@ class Manager implements IManager { } $task->setStatus(OCPTask::STATUS_SCHEDULED); [$provider, ] = $this->getPreferredProviders($task); - if ($provider instanceof IProvider2) { + if ($provider instanceof IProviderWithExpectedRuntime) { $completionExpectedAt = new \DateTime('now'); $completionExpectedAt->add(new \DateInterval('PT'.$provider->getExpectedRuntime().'S')); $task->setCompletionExpectedAt($completionExpectedAt); @@ -183,7 +183,7 @@ class Manager implements IManager { $maxExecutionTime = (int) ini_get('max_execution_time'); // Offload the task to a background job if the expected runtime of the likely provider is longer than 80% of our max execution time // or if the provider doesn't provide a getExpectedRuntime() method - if (!$provider instanceof IProvider2 || $provider->getExpectedRuntime() > $maxExecutionTime * 0.8) { + if (!$provider instanceof IProviderWithExpectedRuntime || $provider->getExpectedRuntime() > $maxExecutionTime * 0.8) { $this->scheduleTask($task); return false; } diff --git a/lib/public/TextProcessing/IProvider2.php b/lib/public/TextProcessing/IProvider2.php deleted file mode 100644 index 74e6a47fed5..00000000000 --- a/lib/public/TextProcessing/IProvider2.php +++ /dev/null @@ -1,48 +0,0 @@ - - * - * @author Marcel Klehr - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - - -namespace OCP\TextProcessing; - -/** - * This interface supersedes IProvider. It allows the system to learn - * the provider's expected runtime and lets the provider know which user is running a task - * @since 28.0.0 - * @template T of ITaskType - * @template-extends IProvider - */ -interface IProvider2 extends IProvider { - /** - * @param ?string $userId the current user's id - * @since 28.0.0 - */ - public function setUserId(?string $userId): string; - - /** - * @return int The expected average runtime of a task in seconds - * @since 28.0.0 - */ - public function getExpectedRuntime(): int; -} diff --git a/lib/public/TextProcessing/IProviderWithExpectedRuntime.php b/lib/public/TextProcessing/IProviderWithExpectedRuntime.php new file mode 100644 index 00000000000..6eb3dcc8cde --- /dev/null +++ b/lib/public/TextProcessing/IProviderWithExpectedRuntime.php @@ -0,0 +1,42 @@ + + * + * @author Marcel Klehr + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + + +namespace OCP\TextProcessing; + +/** + * This interface allows the system to learn the provider's expected runtime + * @since 28.0.0 + * @template T of ITaskType + * @template-extends IProvider + */ +interface IProviderWithExpectedRuntime extends IProvider { + + /** + * @return int The expected average runtime of a task in seconds + * @since 28.0.0 + */ + public function getExpectedRuntime(): int; +} diff --git a/lib/public/TextProcessing/IProviderWithUserId.php b/lib/public/TextProcessing/IProviderWithUserId.php new file mode 100644 index 00000000000..e12317f52f7 --- /dev/null +++ b/lib/public/TextProcessing/IProviderWithUserId.php @@ -0,0 +1,41 @@ + + * + * @author Marcel Klehr + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + + +namespace OCP\TextProcessing; + +/** + * This interface allows providers to access the user that initiated the task being run. + * @since 28.0.0 + * @template T of ITaskType + * @template-extends IProvider + */ +interface IProviderWithUserId extends IProvider { + /** + * @param ?string $userId the current user's id + * @since 28.0.0 + */ + public function setUserId(?string $userId): string; +} diff --git a/lib/public/TextProcessing/Task.php b/lib/public/TextProcessing/Task.php index f6b3a1a6a42..25b7132ee31 100644 --- a/lib/public/TextProcessing/Task.php +++ b/lib/public/TextProcessing/Task.php @@ -93,13 +93,13 @@ final class Task implements \JsonSerializable { /** * @psalm-param P $provider - * @param IProvider|IProvider2 $provider + * @param IProvider $provider * @return string * @since 27.1.0 */ - public function visitProvider(IProvider|IProvider2 $provider): string { + public function visitProvider(IProvider $provider): string { if ($this->canUseProvider($provider)) { - if ($provider instanceof IProvider2) { + if ($provider instanceof IProviderWithUserId) { $provider->setUserId($this->getUserId()); } return $provider->process($this->getInput()); -- cgit v1.2.3 From b8862bd14ed778b6de107b1e2ba495ef5e5fc896 Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Tue, 7 Nov 2023 16:29:15 +0100 Subject: fix coding style Signed-off-by: Marcel Klehr --- lib/public/TextProcessing/IProviderWithExpectedRuntime.php | 1 - 1 file changed, 1 deletion(-) (limited to 'lib/public/TextProcessing') diff --git a/lib/public/TextProcessing/IProviderWithExpectedRuntime.php b/lib/public/TextProcessing/IProviderWithExpectedRuntime.php index 6eb3dcc8cde..17767fc02d4 100644 --- a/lib/public/TextProcessing/IProviderWithExpectedRuntime.php +++ b/lib/public/TextProcessing/IProviderWithExpectedRuntime.php @@ -33,7 +33,6 @@ namespace OCP\TextProcessing; * @template-extends IProvider */ interface IProviderWithExpectedRuntime extends IProvider { - /** * @return int The expected average runtime of a task in seconds * @since 28.0.0 -- cgit v1.2.3 From 8fe993c06fdff6f9c6c1f502244cb4db79408f4c Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Wed, 8 Nov 2023 16:58:31 +0100 Subject: fix: Remove ITaskTypeWithId Signed-off-by: Marcel Klehr --- lib/public/TextProcessing/IProvider.php | 2 +- lib/public/TextProcessing/IProviderWithId.php | 3 ++- lib/public/TextProcessing/ITaskTypeWithId.php | 37 --------------------------- lib/public/TextProcessing/Task.php | 4 +-- 4 files changed, 5 insertions(+), 41 deletions(-) delete mode 100644 lib/public/TextProcessing/ITaskTypeWithId.php (limited to 'lib/public/TextProcessing') diff --git a/lib/public/TextProcessing/IProvider.php b/lib/public/TextProcessing/IProvider.php index 01c17f4bfbf..6132e60b493 100644 --- a/lib/public/TextProcessing/IProvider.php +++ b/lib/public/TextProcessing/IProvider.php @@ -56,7 +56,7 @@ interface IProvider { * provider handles * * @since 27.1.0 - * @return class-string|string + * @return class-string */ public function getTaskType(): string; } diff --git a/lib/public/TextProcessing/IProviderWithId.php b/lib/public/TextProcessing/IProviderWithId.php index 6723168988e..f7b6ecfda0e 100644 --- a/lib/public/TextProcessing/IProviderWithId.php +++ b/lib/public/TextProcessing/IProviderWithId.php @@ -27,7 +27,8 @@ namespace OCP\TextProcessing; /** * @since 28.0.0 - * @extends IProvider + * @extends IProvider + * @template T of ITaskType */ interface IProviderWithId extends IProvider { diff --git a/lib/public/TextProcessing/ITaskTypeWithId.php b/lib/public/TextProcessing/ITaskTypeWithId.php deleted file mode 100644 index b86b831f266..00000000000 --- a/lib/public/TextProcessing/ITaskTypeWithId.php +++ /dev/null @@ -1,37 +0,0 @@ - - * - * @author Marcel Klehr - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - */ - -namespace OCP\TextProcessing; - -/** - * @since 28.0.0 - */ -interface ITaskTypeWithId { - /** - * The id of this provider - * @since 28.0.0 - */ - public function getId(): string; -} diff --git a/lib/public/TextProcessing/Task.php b/lib/public/TextProcessing/Task.php index 52a7637bd7c..446e414cb04 100644 --- a/lib/public/TextProcessing/Task.php +++ b/lib/public/TextProcessing/Task.php @@ -29,8 +29,8 @@ namespace OCP\TextProcessing; * This is a text processing task * @since 27.1.0 * @psalm-template T of ITaskType - * @psalm-template S as class-string | string - * @psalm-template P as IProvider | IProvider + * @psalm-template S as class-string + * @psalm-template P as IProvider */ final class Task implements \JsonSerializable { protected ?int $id = null; -- cgit v1.2.3 From a29ed70c6cac8284f1de029b66b2798b6a16d519 Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Wed, 8 Nov 2023 17:01:10 +0100 Subject: Update lib/public/TextProcessing/IProviderWithUserId.php Co-authored-by: Julien Veyssier Signed-off-by: Marcel Klehr --- lib/public/TextProcessing/IProviderWithUserId.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/public/TextProcessing') diff --git a/lib/public/TextProcessing/IProviderWithUserId.php b/lib/public/TextProcessing/IProviderWithUserId.php index e12317f52f7..0a01a4c56c4 100644 --- a/lib/public/TextProcessing/IProviderWithUserId.php +++ b/lib/public/TextProcessing/IProviderWithUserId.php @@ -37,5 +37,5 @@ interface IProviderWithUserId extends IProvider { * @param ?string $userId the current user's id * @since 28.0.0 */ - public function setUserId(?string $userId): string; + public function setUserId(?string $userId): void; } -- cgit v1.2.3 From ab736429ce1bf126bd8b1bef1db4cac9a31e139e Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Wed, 8 Nov 2023 17:02:00 +0100 Subject: fix: Make linters happy Signed-off-by: Marcel Klehr --- lib/composer/composer/autoload_classmap.php | 1 + lib/composer/composer/autoload_static.php | 1 + lib/public/TextProcessing/IProviderWithId.php | 1 - 3 files changed, 2 insertions(+), 1 deletion(-) (limited to 'lib/public/TextProcessing') diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 548d930e758..d57b1925d8e 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -668,6 +668,7 @@ return array( 'OCP\\TextProcessing\\HeadlineTaskType' => $baseDir . '/lib/public/TextProcessing/HeadlineTaskType.php', 'OCP\\TextProcessing\\IManager' => $baseDir . '/lib/public/TextProcessing/IManager.php', 'OCP\\TextProcessing\\IProvider' => $baseDir . '/lib/public/TextProcessing/IProvider.php', + 'OCP\\TextProcessing\\IProviderWithId' => $baseDir . '/lib/public/TextProcessing/IProviderWithId.php', 'OCP\\TextProcessing\\ITaskType' => $baseDir . '/lib/public/TextProcessing/ITaskType.php', 'OCP\\TextProcessing\\SummaryTaskType' => $baseDir . '/lib/public/TextProcessing/SummaryTaskType.php', 'OCP\\TextProcessing\\Task' => $baseDir . '/lib/public/TextProcessing/Task.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 4af4beb4867..768a7a956e0 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -701,6 +701,7 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2 'OCP\\TextProcessing\\HeadlineTaskType' => __DIR__ . '/../../..' . '/lib/public/TextProcessing/HeadlineTaskType.php', 'OCP\\TextProcessing\\IManager' => __DIR__ . '/../../..' . '/lib/public/TextProcessing/IManager.php', 'OCP\\TextProcessing\\IProvider' => __DIR__ . '/../../..' . '/lib/public/TextProcessing/IProvider.php', + 'OCP\\TextProcessing\\IProviderWithId' => __DIR__ . '/../../..' . '/lib/public/TextProcessing/IProviderWithId.php', 'OCP\\TextProcessing\\ITaskType' => __DIR__ . '/../../..' . '/lib/public/TextProcessing/ITaskType.php', 'OCP\\TextProcessing\\SummaryTaskType' => __DIR__ . '/../../..' . '/lib/public/TextProcessing/SummaryTaskType.php', 'OCP\\TextProcessing\\Task' => __DIR__ . '/../../..' . '/lib/public/TextProcessing/Task.php', diff --git a/lib/public/TextProcessing/IProviderWithId.php b/lib/public/TextProcessing/IProviderWithId.php index f7b6ecfda0e..1bd02278d1c 100644 --- a/lib/public/TextProcessing/IProviderWithId.php +++ b/lib/public/TextProcessing/IProviderWithId.php @@ -31,7 +31,6 @@ namespace OCP\TextProcessing; * @template T of ITaskType */ interface IProviderWithId extends IProvider { - /** * The id of this provider * @since 28.0.0 -- cgit v1.2.3 From fe6d9e33b47dfc06e9e161971bd2b62532208fa5 Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Wed, 29 Nov 2023 10:55:12 +0100 Subject: fix(TextProcessing): Make task type template param covariant Signed-off-by: Marcel Klehr --- lib/public/TextProcessing/IProvider.php | 2 +- lib/public/TextProcessing/Task.php | 14 ++++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) (limited to 'lib/public/TextProcessing') diff --git a/lib/public/TextProcessing/IProvider.php b/lib/public/TextProcessing/IProvider.php index 6132e60b493..fc57add1835 100644 --- a/lib/public/TextProcessing/IProvider.php +++ b/lib/public/TextProcessing/IProvider.php @@ -31,7 +31,7 @@ use RuntimeException; /** * This is the interface that is implemented by apps that * implement a text processing provider - * @template T of ITaskType + * @psalm-template-covariant T of ITaskType * @since 27.1.0 */ interface IProvider { diff --git a/lib/public/TextProcessing/Task.php b/lib/public/TextProcessing/Task.php index 25b7132ee31..c62b7b2fff8 100644 --- a/lib/public/TextProcessing/Task.php +++ b/lib/public/TextProcessing/Task.php @@ -28,9 +28,7 @@ namespace OCP\TextProcessing; /** * This is a text processing task * @since 27.1.0 - * @psalm-template T of ITaskType - * @psalm-template S as class-string - * @psalm-template P as IProvider + * @psalm-template-covariant T of ITaskType */ final class Task implements \JsonSerializable { protected ?int $id = null; @@ -74,7 +72,7 @@ final class Task implements \JsonSerializable { protected int $status = self::STATUS_UNKNOWN; /** - * @psalm-param S $type + * @psalm-param class-string $type * @param string $type * @param string $input * @param string $appId @@ -92,7 +90,7 @@ final class Task implements \JsonSerializable { } /** - * @psalm-param P $provider + * @psalm-param IProvider $provider * @param IProvider $provider * @return string * @since 27.1.0 @@ -109,7 +107,7 @@ final class Task implements \JsonSerializable { } /** - * @psalm-param P $provider + * @psalm-param IProvider $provider * @param IProvider $provider * @return bool * @since 27.1.0 @@ -119,7 +117,7 @@ final class Task implements \JsonSerializable { } /** - * @psalm-return S + * @psalm-return class-string * @since 27.1.0 */ final public function getType(): string { @@ -207,7 +205,7 @@ final class Task implements \JsonSerializable { } /** - * @psalm-return array{id: ?int, type: S, status: 0|1|2|3|4, userId: ?string, appId: string, input: string, output: ?string, identifier: string, completionExpectedAt: ?int} + * @psalm-return array{id: ?int, type: class-string, status: 0|1|2|3|4, userId: ?string, appId: string, input: string, output: ?string, identifier: string, completionExpectedAt: ?int} * @since 27.1.0 */ public function jsonSerialize(): array { -- cgit v1.2.3