Skip to content

Commit 92bb9ac

Browse files
committed
feat(taskprocessing): add an endpoint to get the position of a scheduled task in the queue
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
1 parent bff9aaf commit 92bb9ac

7 files changed

Lines changed: 718 additions & 0 deletions

File tree

core/Controller/TaskProcessingApiController.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,31 @@ public function cancelTaskExAppEndpoint(int $taskId): DataResponse {
740740
return $this->handleCancelTaskInternal($taskId);
741741
}
742742

743+
/**
744+
* Get a task's position in the queue
745+
*
746+
* @param int $taskId The id of the task
747+
* @return DataResponse<Http::STATUS_OK, int, array{}>|DataResponse<Http::STATUS_INTERNAL_SERVER_ERROR|Http::STATUS_NOT_FOUND|Http::STATUS_PRECONDITION_FAILED, array{message: string}, array{}>
748+
*
749+
* 200: The position was found
750+
* 404: Task not found
751+
* 412: The task is not scheduled
752+
*/
753+
#[NoAdminRequired]
754+
#[ApiRoute(verb: 'GET', url: '/tasks/{taskId}/queue_position', root: '/taskprocessing')]
755+
public function getTaskQueuePosition(int $taskId): DataResponse {
756+
try {
757+
$position = $this->taskProcessingManager->getTaskQueuePosition($taskId, $this->userId);
758+
return new DataResponse($position);
759+
} catch (NotFoundException) {
760+
return new DataResponse(['message' => $this->l->t('Task not found')], Http::STATUS_NOT_FOUND);
761+
} catch (PreConditionNotMetException $e) {
762+
return new DataResponse(['message' => $e->getMessage()], Http::STATUS_PRECONDITION_FAILED);
763+
} catch (Exception) {
764+
return new DataResponse(['message' => $this->l->t('Internal error')], Http::STATUS_INTERNAL_SERVER_ERROR);
765+
}
766+
}
767+
743768
/**
744769
* Returns the next scheduled task for the taskTypeId
745770
*

core/openapi-full.json

Lines changed: 214 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6321,6 +6321,220 @@
63216321
}
63226322
}
63236323
},
6324+
"/ocs/v2.php/taskprocessing/tasks/{taskId}/queue_position": {
6325+
"get": {
6326+
"operationId": "task_processing_api-get-task-queue-position",
6327+
"summary": "Get a task's position in the queue",
6328+
"tags": [
6329+
"task_processing_api"
6330+
],
6331+
"security": [
6332+
{
6333+
"bearer_auth": []
6334+
},
6335+
{
6336+
"basic_auth": []
6337+
}
6338+
],
6339+
"parameters": [
6340+
{
6341+
"name": "taskId",
6342+
"in": "path",
6343+
"description": "The id of the task",
6344+
"required": true,
6345+
"schema": {
6346+
"type": "integer",
6347+
"format": "int64"
6348+
}
6349+
},
6350+
{
6351+
"name": "OCS-APIRequest",
6352+
"in": "header",
6353+
"description": "Required to be true for the API request to pass",
6354+
"required": true,
6355+
"schema": {
6356+
"type": "boolean",
6357+
"default": true
6358+
}
6359+
}
6360+
],
6361+
"responses": {
6362+
"200": {
6363+
"description": "The position was found",
6364+
"content": {
6365+
"application/json": {
6366+
"schema": {
6367+
"type": "object",
6368+
"required": [
6369+
"ocs"
6370+
],
6371+
"properties": {
6372+
"ocs": {
6373+
"type": "object",
6374+
"required": [
6375+
"meta",
6376+
"data"
6377+
],
6378+
"properties": {
6379+
"meta": {
6380+
"$ref": "#/components/schemas/OCSMeta"
6381+
},
6382+
"data": {
6383+
"type": "integer",
6384+
"format": "int64"
6385+
}
6386+
}
6387+
}
6388+
}
6389+
}
6390+
}
6391+
}
6392+
},
6393+
"500": {
6394+
"description": "",
6395+
"content": {
6396+
"application/json": {
6397+
"schema": {
6398+
"type": "object",
6399+
"required": [
6400+
"ocs"
6401+
],
6402+
"properties": {
6403+
"ocs": {
6404+
"type": "object",
6405+
"required": [
6406+
"meta",
6407+
"data"
6408+
],
6409+
"properties": {
6410+
"meta": {
6411+
"$ref": "#/components/schemas/OCSMeta"
6412+
},
6413+
"data": {
6414+
"type": "object",
6415+
"required": [
6416+
"message"
6417+
],
6418+
"properties": {
6419+
"message": {
6420+
"type": "string"
6421+
}
6422+
}
6423+
}
6424+
}
6425+
}
6426+
}
6427+
}
6428+
}
6429+
}
6430+
},
6431+
"404": {
6432+
"description": "Task not found",
6433+
"content": {
6434+
"application/json": {
6435+
"schema": {
6436+
"type": "object",
6437+
"required": [
6438+
"ocs"
6439+
],
6440+
"properties": {
6441+
"ocs": {
6442+
"type": "object",
6443+
"required": [
6444+
"meta",
6445+
"data"
6446+
],
6447+
"properties": {
6448+
"meta": {
6449+
"$ref": "#/components/schemas/OCSMeta"
6450+
},
6451+
"data": {
6452+
"type": "object",
6453+
"required": [
6454+
"message"
6455+
],
6456+
"properties": {
6457+
"message": {
6458+
"type": "string"
6459+
}
6460+
}
6461+
}
6462+
}
6463+
}
6464+
}
6465+
}
6466+
}
6467+
}
6468+
},
6469+
"412": {
6470+
"description": "The task is not scheduled",
6471+
"content": {
6472+
"application/json": {
6473+
"schema": {
6474+
"type": "object",
6475+
"required": [
6476+
"ocs"
6477+
],
6478+
"properties": {
6479+
"ocs": {
6480+
"type": "object",
6481+
"required": [
6482+
"meta",
6483+
"data"
6484+
],
6485+
"properties": {
6486+
"meta": {
6487+
"$ref": "#/components/schemas/OCSMeta"
6488+
},
6489+
"data": {
6490+
"type": "object",
6491+
"required": [
6492+
"message"
6493+
],
6494+
"properties": {
6495+
"message": {
6496+
"type": "string"
6497+
}
6498+
}
6499+
}
6500+
}
6501+
}
6502+
}
6503+
}
6504+
}
6505+
}
6506+
},
6507+
"401": {
6508+
"description": "Current user is not logged in",
6509+
"content": {
6510+
"application/json": {
6511+
"schema": {
6512+
"type": "object",
6513+
"required": [
6514+
"ocs"
6515+
],
6516+
"properties": {
6517+
"ocs": {
6518+
"type": "object",
6519+
"required": [
6520+
"meta",
6521+
"data"
6522+
],
6523+
"properties": {
6524+
"meta": {
6525+
"$ref": "#/components/schemas/OCSMeta"
6526+
},
6527+
"data": {}
6528+
}
6529+
}
6530+
}
6531+
}
6532+
}
6533+
}
6534+
}
6535+
}
6536+
}
6537+
},
63246538
"/ocs/v2.php/teams/{teamId}/resources": {
63256539
"get": {
63266540
"operationId": "teams_api-resolve-one",

0 commit comments

Comments
 (0)