diff --git a/core/Controller/TaskProcessingApiController.php b/core/Controller/TaskProcessingApiController.php index 9783299bccb1c..d81e78fad16ad 100644 --- a/core/Controller/TaskProcessingApiController.php +++ b/core/Controller/TaskProcessingApiController.php @@ -418,4 +418,32 @@ public function cancelTask(int $taskId): DataResponse { return new DataResponse(['message' => $this->l->t('Internal error')], Http::STATUS_INTERNAL_SERVER_ERROR); } } + + /** + * Returns the next scheduled task for the taskTypeId + * + * @param string $taskTypeId The id of the task type + * @return DataResponse|DataResponse|DataResponse + * + * 200: Task returned + * 204: No task found + */ + #[NoAdminRequired] + #[ApiRoute(verb: 'GET', url: '/tasks/next', root: '/taskprocessing')] + public function getNextScheduledTask(string $taskTypeId): DataResponse { + try { + $task = $this->taskProcessingManager->getNextScheduledTask($taskTypeId); + + /** @var CoreTaskProcessingTask $json */ + $json = $task->jsonSerialize(); + + return new DataResponse([ + 'task' => $json, + ]); + } catch (\OCP\TaskProcessing\Exception\NotFoundException $e) { + return new DataResponse(null, Http::STATUS_NO_CONTENT); + } catch (Exception $e) { + return new DataResponse(['message' => $this->l->t('Internal error')], Http::STATUS_INTERNAL_SERVER_ERROR); + } + } } diff --git a/core/openapi.json b/core/openapi.json index a20691046fa7a..02a06c15a7ba2 100644 --- a/core/openapi.json +++ b/core/openapi.json @@ -4824,6 +4824,125 @@ } } }, + "/ocs/v2.php/taskprocessing/tasks/next": { + "get": { + "operationId": "task_processing_api-get-next-scheduled-task", + "summary": "Returns the next scheduled task for the taskTypeId", + "tags": [ + "task_processing_api" + ], + "security": [ + { + "bearer_auth": [] + }, + { + "basic_auth": [] + } + ], + "parameters": [ + { + "name": "taskTypeId", + "in": "query", + "description": "The id of the task type", + "required": true, + "schema": { + "type": "string" + } + }, + { + "name": "OCS-APIRequest", + "in": "header", + "description": "Required to be true for the API request to pass", + "required": true, + "schema": { + "type": "boolean", + "default": true + } + } + ], + "responses": { + "200": { + "description": "Task returned", + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "ocs" + ], + "properties": { + "ocs": { + "type": "object", + "required": [ + "meta", + "data" + ], + "properties": { + "meta": { + "$ref": "#/components/schemas/OCSMeta" + }, + "data": { + "type": "object", + "required": [ + "task" + ], + "properties": { + "task": { + "$ref": "#/components/schemas/TaskProcessingTask" + } + } + } + } + } + } + } + } + } + }, + "204": { + "description": "No task found" + }, + "500": { + "description": "", + "content": { + "application/json": { + "schema": { + "type": "object", + "required": [ + "ocs" + ], + "properties": { + "ocs": { + "type": "object", + "required": [ + "meta", + "data" + ], + "properties": { + "meta": { + "$ref": "#/components/schemas/OCSMeta" + }, + "data": { + "type": "object", + "required": [ + "message" + ], + "properties": { + "message": { + "type": "string" + } + } + } + } + } + } + } + } + } + } + } + } + }, "/ocs/v2.php/teams/{teamId}/resources": { "get": { "operationId": "teams_api-resolve-one",