diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/Controller/TextProcessingApiController.php | 12 | ||||
-rw-r--r-- | core/Migrations/Version28000Date20231103104802.php | 61 | ||||
-rw-r--r-- | core/ResponseDefinitions.php | 1 | ||||
-rw-r--r-- | core/openapi.json | 46 |
4 files changed, 117 insertions, 3 deletions
diff --git a/core/Controller/TextProcessingApiController.php b/core/Controller/TextProcessingApiController.php index 8b5175f0e5c..a6b85fd46ae 100644 --- a/core/Controller/TextProcessingApiController.php +++ b/core/Controller/TextProcessingApiController.php @@ -35,8 +35,10 @@ 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\Exception\TaskFailureException; use OCP\TextProcessing\ITaskType; use OCP\TextProcessing\Task; use OCP\TextProcessing\IManager; @@ -102,7 +104,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<Http::STATUS_OK, array{task: CoreTextProcessingTask}, array{}>|DataResponse<Http::STATUS_BAD_REQUEST|Http::STATUS_PRECONDITION_FAILED, array{message: string}, array{}> + * @return DataResponse<Http::STATUS_OK, array{task: CoreTextProcessingTask}, array{}>|DataResponse<Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_BAD_REQUEST|Http::STATUS_PRECONDITION_FAILED, array{message: string}, array{}> * * 200: Task scheduled successfully * 400: Scheduling task is not possible @@ -118,7 +120,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(TaskFailureException) { + // noop, because the task object has the failure status set already, we just return the task json + } $json = $task->jsonSerialize(); @@ -127,6 +133,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..aa54f1c5848 --- /dev/null +++ b/core/Migrations/Version28000Date20231103104802.php @@ -0,0 +1,61 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright Copyright (c) 2023 Marcel Klehr <mklehr@gmx.net> + * + * @author Marcel Klehr <mklehr@gmx.net> + * + * @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 <http://www.gnu.org/licenses/>. + * + */ + +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'); + + if (!$table->hasColumn('completion_expected_at')) { + $table->addColumn('completion_expected_at', Types::DATETIME, [ + 'notnull' => false, + ]); + return $schema; + } + } + + return null; + } +} diff --git a/core/ResponseDefinitions.php b/core/ResponseDefinitions.php index 86eef1d2524..7d54cf66061 100644 --- a/core/ResponseDefinitions.php +++ b/core/ResponseDefinitions.php @@ -147,6 +147,7 @@ namespace OCA\Core; * input: string, * output: ?string, * identifier: string, + * completionExpectedAt: ?int * } * * @psalm-type CoreTextToImageTask = array{ diff --git a/core/openapi.json b/core/openapi.json index a63d9380db7..b703cfff79f 100644 --- a/core/openapi.json +++ b/core/openapi.json @@ -416,7 +416,8 @@ "appId", "input", "output", - "identifier" + "identifier", + "completionExpectedAt" ], "properties": { "id": { @@ -447,6 +448,11 @@ }, "identifier": { "type": "string" + }, + "completionExpectedAt": { + "type": "integer", + "format": "int64", + "nullable": true } } }, @@ -4684,6 +4690,44 @@ } } }, + "500": { + "description": "", + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "ocs" + ], + "properties": { + "ocs": { + "type": "object", + "required": [ + "meta", + "data" + ], + "properties": { + "meta": { + "$ref": "#/components/schemas/OCSMeta" + }, + "data": { + "type": "object", + "required": [ + "message" + ], + "properties": { + "message": { + "type": "string" + } + } + } + } + } + } + } + } + } + }, "400": { "description": "Scheduling task is not possible", "content": { |