mirror of
https://github.com/nextcloud/server.git
synced 2026-06-10 17:23:59 -04:00
fix(TextProcessing/Manager): Throw TaskFailureException upon failure
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
This commit is contained in:
parent
181f819e41
commit
d11b9cbd79
4 changed files with 15 additions and 10 deletions
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace OCP\TextProcessing\Exception;
|
||||
|
||||
class TaskFailureException extends \RuntimeException {
|
||||
|
||||
}
|
||||
|
|
@ -29,6 +29,7 @@ namespace OCP\TextProcessing;
|
|||
use OCP\Common\Exception\NotFoundException;
|
||||
use OCP\DB\Exception;
|
||||
use OCP\PreConditionNotMetException;
|
||||
use OCP\TextProcessing\Exception\TaskFailureException;
|
||||
use RuntimeException;
|
||||
|
||||
/**
|
||||
|
|
@ -57,7 +58,7 @@ interface IManager {
|
|||
/**
|
||||
* @param Task $task The task to run
|
||||
* @throws PreConditionNotMetException If no or not the requested provider was registered but this method was still called
|
||||
* @throws RuntimeException If something else failed
|
||||
* @throws TaskFailureException If running the task failed
|
||||
* @since 27.1.0
|
||||
*/
|
||||
public function runTask(Task $task): string;
|
||||
|
|
@ -82,7 +83,7 @@ interface IManager {
|
|||
* @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 TaskFailureException If running the task failed
|
||||
* @throws Exception storing the task in the database failed
|
||||
* @since 28.0.0
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in a new issue