Skip to content

Commit

Permalink
feat(TaskProcessingApi): Add endpoint for getting the next task
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <kate@provokateurin.de>
  • Loading branch information
provokateurin committed May 17, 2024
1 parent 7bc4ccb commit 5800675
Show file tree
Hide file tree
Showing 2 changed files with 147 additions and 0 deletions.
28 changes: 28 additions & 0 deletions core/Controller/TaskProcessingApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<Http::STATUS_OK, array{task: CoreTaskProcessingTask}, array{}>|DataResponse<Http::STATUS_NO_CONTENT, null, array{}>|DataResponse<Http::STATUS_INTERNAL_SERVER_ERROR, array{message: string}, array{}>
*
* 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);
}
}
}
119 changes: 119 additions & 0 deletions core/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 5800675

Please sign in to comment.