mirror of
https://github.com/nextcloud/server.git
synced 2026-06-11 01:30:50 -04:00
feat(task-streaming): add an endpoint to set a task intermediate output
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
This commit is contained in:
parent
ee9171ba7a
commit
3307c3aeb5
3 changed files with 42 additions and 1 deletions
|
|
@ -645,6 +645,37 @@ class TaskProcessingApiController extends OCSController {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the task intermediate result while it is running
|
||||
*
|
||||
* @param int $taskId The id of the task
|
||||
* @param array<string,mixed>|null $output The intermediate task output, files are represented by their IDs
|
||||
* @return DataResponse<Http::STATUS_OK, array{task: CoreTaskProcessingTask}, array{}>|DataResponse<Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND, array{message: string}, array{}>
|
||||
*
|
||||
* 200: Result updated successfully
|
||||
* 404: Task not found
|
||||
*/
|
||||
#[ExAppRequired]
|
||||
#[ApiRoute(verb: 'POST', url: '/tasks_provider/{taskId}/stream-result', root: '/taskprocessing')]
|
||||
public function setIntermediateResult(int $taskId, array $output): DataResponse {
|
||||
try {
|
||||
// set result
|
||||
$this->taskProcessingManager->setTaskIntermediateOutput($taskId, $output);
|
||||
$task = $this->taskProcessingManager->getTask($taskId);
|
||||
|
||||
/** @var CoreTaskProcessingTask $json */
|
||||
$json = $task->jsonSerialize();
|
||||
|
||||
return new DataResponse([
|
||||
'task' => $json,
|
||||
]);
|
||||
} catch (NotFoundException) {
|
||||
return new DataResponse(['message' => $this->l->t('Not found')], Http::STATUS_NOT_FOUND);
|
||||
} catch (Exception) {
|
||||
return new DataResponse(['message' => $this->l->t('Internal error')], Http::STATUS_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return DataResponse<Http::STATUS_OK, array{task: CoreTaskProcessingTask}, array{}>|DataResponse<Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND, array{message: string}, array{}>
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -1227,7 +1227,7 @@ class Manager implements IManager {
|
|||
public function setTaskIntermediateOutput(int $id, array $output): bool {
|
||||
// TODO: Not sure if we should rather catch the exceptions of getTask here and fail silently
|
||||
$task = $this->getTask($id);
|
||||
if ($task->getStatus() === Task::STATUS_CANCELLED) {
|
||||
if ($task->getStatus() !== Task::STATUS_RUNNING) {
|
||||
return false;
|
||||
}
|
||||
$userId = $task->getUserId();
|
||||
|
|
|
|||
|
|
@ -143,6 +143,16 @@ interface IManager {
|
|||
*/
|
||||
public function setTaskResult(int $id, ?string $error, ?array $result, bool $isUsingFileIds = false, ?string $userFacingError = null): void;
|
||||
|
||||
/**
|
||||
* @param int $id The id of the task
|
||||
* @param array $output
|
||||
* @return bool `true` if the task should still be running; `false` if the task has been cancelled in the meantime
|
||||
* @throws Exception If the query failed
|
||||
* @throws NotFoundException If the task could not be found
|
||||
* @since 34.0.0
|
||||
*/
|
||||
public function setTaskIntermediateOutput(int $id, array $output): bool;
|
||||
|
||||
/**
|
||||
* @param int $id
|
||||
* @param float $progress
|
||||
|
|
|
|||
Loading…
Reference in a new issue