summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/Controller/TextProcessingApiController.php11
-rw-r--r--core/Migrations/Version28000Date20231103104802.php60
-rw-r--r--core/ResponseDefinitions.php1
3 files changed, 70 insertions, 2 deletions
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<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 +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 @@
+<?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');
+
+ $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{