Skip to content

Commit 6d42d50

Browse files
committed
feat(taskprocessing): Add queue_stats API endpoint for external autoscalers
Signed-off-by: Oleksander Piskun <oleksandr2088@icloud.com>
1 parent 9beed5c commit 6d42d50

File tree

7 files changed

+615
-0
lines changed

7 files changed

+615
-0
lines changed

core/Controller/TaskProcessingApiController.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,34 @@ public function listTasks(?string $taskType, ?string $customId = null): DataResp
424424
}
425425
}
426426

427+
/**
428+
* Returns queue statistics for task processing
429+
*
430+
* Returns the count of scheduled and running tasks, optionally filtered
431+
* by task type(s). Designed for external scalers (e.g. KEDA) to poll
432+
* for task queue depth. Admin-only endpoint authenticated via app_password.
433+
*
434+
* @param list<string> $taskTypeIds List of task type IDs to filter by
435+
* @return DataResponse<Http::STATUS_OK, array{scheduled: int, running: int}, array{}>|DataResponse<Http::STATUS_INTERNAL_SERVER_ERROR, array{message: string}, array{}>
436+
*
437+
* 200: Queue stats returned
438+
*/
439+
#[NoCSRFRequired]
440+
#[ApiRoute(verb: 'GET', url: '/queue_stats', root: '/taskprocessing')]
441+
public function queueStats(array $taskTypeIds = []): DataResponse {
442+
try {
443+
$scheduled = $this->taskProcessingManager->countTasks(Task::STATUS_SCHEDULED, $taskTypeIds);
444+
$running = $this->taskProcessingManager->countTasks(Task::STATUS_RUNNING, $taskTypeIds);
445+
446+
return new DataResponse([
447+
'scheduled' => $scheduled,
448+
'running' => $running,
449+
]);
450+
} catch (Exception) {
451+
return new DataResponse(['message' => $this->l->t('Internal error')], Http::STATUS_INTERNAL_SERVER_ERROR);
452+
}
453+
}
454+
427455
/**
428456
* Returns the contents of a file referenced in a task
429457
*

core/openapi-administration.json

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,188 @@
129129
}
130130
},
131131
"paths": {
132+
"/ocs/v2.php/taskprocessing/queue_stats": {
133+
"get": {
134+
"operationId": "task_processing_api-queue-stats",
135+
"summary": "Returns queue statistics for task processing",
136+
"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",
137+
"tags": [
138+
"task_processing_api"
139+
],
140+
"security": [
141+
{
142+
"bearer_auth": []
143+
},
144+
{
145+
"basic_auth": []
146+
}
147+
],
148+
"parameters": [
149+
{
150+
"name": "taskTypeIds[]",
151+
"in": "query",
152+
"description": "List of task type IDs to filter by",
153+
"schema": {
154+
"type": "array",
155+
"default": [],
156+
"items": {
157+
"type": "string"
158+
}
159+
}
160+
},
161+
{
162+
"name": "OCS-APIRequest",
163+
"in": "header",
164+
"description": "Required to be true for the API request to pass",
165+
"required": true,
166+
"schema": {
167+
"type": "boolean",
168+
"default": true
169+
}
170+
}
171+
],
172+
"responses": {
173+
"200": {
174+
"description": "Queue stats returned",
175+
"content": {
176+
"application/json": {
177+
"schema": {
178+
"type": "object",
179+
"required": [
180+
"ocs"
181+
],
182+
"properties": {
183+
"ocs": {
184+
"type": "object",
185+
"required": [
186+
"meta",
187+
"data"
188+
],
189+
"properties": {
190+
"meta": {
191+
"$ref": "#/components/schemas/OCSMeta"
192+
},
193+
"data": {
194+
"type": "object",
195+
"required": [
196+
"scheduled",
197+
"running"
198+
],
199+
"properties": {
200+
"scheduled": {
201+
"type": "integer",
202+
"format": "int64"
203+
},
204+
"running": {
205+
"type": "integer",
206+
"format": "int64"
207+
}
208+
}
209+
}
210+
}
211+
}
212+
}
213+
}
214+
}
215+
}
216+
},
217+
"500": {
218+
"description": "",
219+
"content": {
220+
"application/json": {
221+
"schema": {
222+
"type": "object",
223+
"required": [
224+
"ocs"
225+
],
226+
"properties": {
227+
"ocs": {
228+
"type": "object",
229+
"required": [
230+
"meta",
231+
"data"
232+
],
233+
"properties": {
234+
"meta": {
235+
"$ref": "#/components/schemas/OCSMeta"
236+
},
237+
"data": {
238+
"type": "object",
239+
"required": [
240+
"message"
241+
],
242+
"properties": {
243+
"message": {
244+
"type": "string"
245+
}
246+
}
247+
}
248+
}
249+
}
250+
}
251+
}
252+
}
253+
}
254+
},
255+
"401": {
256+
"description": "Current user is not logged in",
257+
"content": {
258+
"application/json": {
259+
"schema": {
260+
"type": "object",
261+
"required": [
262+
"ocs"
263+
],
264+
"properties": {
265+
"ocs": {
266+
"type": "object",
267+
"required": [
268+
"meta",
269+
"data"
270+
],
271+
"properties": {
272+
"meta": {
273+
"$ref": "#/components/schemas/OCSMeta"
274+
},
275+
"data": {}
276+
}
277+
}
278+
}
279+
}
280+
}
281+
}
282+
},
283+
"403": {
284+
"description": "Logged in account must be an admin",
285+
"content": {
286+
"application/json": {
287+
"schema": {
288+
"type": "object",
289+
"required": [
290+
"ocs"
291+
],
292+
"properties": {
293+
"ocs": {
294+
"type": "object",
295+
"required": [
296+
"meta",
297+
"data"
298+
],
299+
"properties": {
300+
"meta": {
301+
"$ref": "#/components/schemas/OCSMeta"
302+
},
303+
"data": {}
304+
}
305+
}
306+
}
307+
}
308+
}
309+
}
310+
}
311+
}
312+
}
313+
},
132314
"/ocs/v2.php/twofactor/state": {
133315
"get": {
134316
"operationId": "two_factor_api-state",

0 commit comments

Comments
 (0)