summaryrefslogtreecommitdiffstats
path: root/core/Controller
diff options
context:
space:
mode:
authorMarcel Klehr <mklehr@gmx.net>2023-11-03 16:22:54 +0100
committerMarcel Klehr <mklehr@gmx.net>2023-11-03 16:22:54 +0100
commit181f819e417a1818f37200f9071fa632c82a0fc2 (patch)
treebbdf2d6a816aa3caa7cf402e63cc520c6cbd67f1 /core/Controller
parentb038dbe0aef8c8680bd4f9075f00d8303338f518 (diff)
downloadnextcloud-server-181f819e417a1818f37200f9071fa632c82a0fc2.tar.gz
nextcloud-server-181f819e417a1818f37200f9071fa632c82a0fc2.zip
enh(TextProcessing): Add IProvider2
- allow providers to obtain current task's userId - allow providers to expose average task runtime Signed-off-by: Marcel Klehr <mklehr@gmx.net>
Diffstat (limited to 'core/Controller')
-rw-r--r--core/Controller/TextProcessingApiController.php11
1 files changed, 9 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);
}
}