Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions core/Controller/TaskProcessingApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,34 @@ public function listTasks(?string $taskType, ?string $customId = null): DataResp
}
}

/**
* Returns queue statistics for task processing
*
* Returns the count of scheduled and running tasks, optionally filtered
* by task type(s). Designed for external scalers (e.g. KEDA) to poll
* for task queue depth. Admin-only endpoint authenticated via app_password.
*
* @param list<string> $taskTypeIds List of task type IDs to filter by
* @return DataResponse<Http::STATUS_OK, array{scheduled_count: int, running_count: int}, array{}>|DataResponse<Http::STATUS_INTERNAL_SERVER_ERROR, array{message: string}, array{}>
*
* 200: Queue stats returned
*/
#[NoCSRFRequired]
#[ApiRoute(verb: 'GET', url: '/queue_stats', root: '/taskprocessing')]
public function queueStats(array $taskTypeIds = []): DataResponse {
try {
$scheduled = $this->taskProcessingManager->countTasks(Task::STATUS_SCHEDULED, $taskTypeIds);
$running = $this->taskProcessingManager->countTasks(Task::STATUS_RUNNING, $taskTypeIds);

return new DataResponse([
'scheduled_count' => $scheduled,
'running_count' => $running,
]);
} catch (Exception) {
return new DataResponse(['message' => $this->l->t('Internal error')], Http::STATUS_INTERNAL_SERVER_ERROR);
}
}

/**
* Returns the contents of a file referenced in a task
*
Expand Down
182 changes: 182 additions & 0 deletions core/openapi-administration.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,188 @@
}
},
"paths": {
"/ocs/v2.php/taskprocessing/queue_stats": {
"get": {
"operationId": "task_processing_api-queue-stats",
"summary": "Returns queue statistics for task processing",
"description": "Returns the count of scheduled and running tasks, optionally filtered by task type(s). Designed for external scalers (e.g. KEDA) to poll for task queue depth. Admin-only endpoint authenticated via app_password.\nThis endpoint requires admin access",
"tags": [
"task_processing_api"
],
"security": [
{
"bearer_auth": []
},
{
"basic_auth": []
}
],
"parameters": [
{
"name": "taskTypeIds[]",
"in": "query",
"description": "List of task type IDs to filter by",
"schema": {
"type": "array",
"default": [],
"items": {
"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": "Queue stats 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": [
"scheduled_count",
"running_count"
],
"properties": {
"scheduled_count": {
"type": "integer",
"format": "int64"
},
"running_count": {
"type": "integer",
"format": "int64"
}
}
}
}
}
}
}
}
}
},
"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"
}
}
}
}
}
}
}
}
}
},
"401": {
"description": "Current user is not logged in",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"ocs"
],
"properties": {
"ocs": {
"type": "object",
"required": [
"meta",
"data"
],
"properties": {
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {}
}
}
}
}
}
}
},
"403": {
"description": "Logged in account must be an admin",
"content": {
"application/json": {
"schema": {
"type": "object",
"required": [
"ocs"
],
"properties": {
"ocs": {
"type": "object",
"required": [
"meta",
"data"
],
"properties": {
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {}
}
}
}
}
}
}
}
}
}
},
"/ocs/v2.php/twofactor/state": {
"get": {
"operationId": "two_factor_api-state",
Expand Down
Loading
Loading