aboutsummaryrefslogtreecommitdiffstats
path: root/core/Controller/TextToImageApiController.php
diff options
context:
space:
mode:
authorMarcel Klehr <mklehr@gmx.net>2023-10-20 12:17:17 +0200
committerMarcel Klehr <mklehr@gmx.net>2023-10-20 12:17:17 +0200
commit8968573d9fa0b9abac1dd5c7684dd94258a080cf (patch)
tree77c83cb8293a72e4b8b4f77dfcb84fe377be7703 /core/Controller/TextToImageApiController.php
parent92cc171a613059f0c15df9bcf26fdf54ef412683 (diff)
downloadnextcloud-server-8968573d9fa0b9abac1dd5c7684dd94258a080cf.tar.gz
nextcloud-server-8968573d9fa0b9abac1dd5c7684dd94258a080cf.zip
enh(TextToImage): Add getExpectedRuntime to IProvider and run tasks during request lifetime if possible
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
Diffstat (limited to 'core/Controller/TextToImageApiController.php')
-rw-r--r--core/Controller/TextToImageApiController.php9
1 files changed, 8 insertions, 1 deletions
diff --git a/core/Controller/TextToImageApiController.php b/core/Controller/TextToImageApiController.php
index 402d2983732..c7878d7cdc3 100644
--- a/core/Controller/TextToImageApiController.php
+++ b/core/Controller/TextToImageApiController.php
@@ -36,6 +36,7 @@ use OCP\AppFramework\Http\Attribute\PublicPage;
use OCP\AppFramework\Http\Attribute\UserRateLimit;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\FileDisplayResponse;
+use OCP\DB\Exception;
use OCP\Files\NotFoundException;
use OCP\IL10N;
use OCP\IRequest;
@@ -91,7 +92,11 @@ class TextToImageApiController extends \OCP\AppFramework\OCSController {
public function schedule(string $input, string $appId, string $identifier = ''): DataResponse {
$task = new Task($input, $appId, $this->userId, $identifier);
try {
- $this->textToImageManager->scheduleTask($task);
+ try {
+ $this->textToImageManager->runOrScheduleTask($task);
+ } catch (\RuntimeException) {
+ // noop
+ }
$json = $task->jsonSerialize();
@@ -100,6 +105,8 @@ class TextToImageApiController extends \OCP\AppFramework\OCSController {
]);
} catch (PreConditionNotMetException) {
return new DataResponse(['message' => $this->l->t('No text to image provider is available')], Http::STATUS_PRECONDITION_FAILED);
+ } catch (Exception) {
+ return new DataResponse(['message' => $this->l->t('Internal error')], Http::STATUS_INTERNAL_SERVER_ERROR);
}
}