Skip to content

Commit 7a374e5

Browse files
feat(TaskProcessing): Add next_task_batch endpoint (#383)
Changes proposed in this pull request: * Adds a method for the [next_batch taskprocessing OCS endpoint](https://docs.nextcloud.com/server/latest/developer_manual/_static/openapi.html#/operations/core-task_processing_api-get-next-scheduled-task-batch) Untested. --------- Signed-off-by: Marcel Klehr <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent d2eb66a commit 7a374e5

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

nc_py_api/ex_app/providers/task_processing.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,23 @@ def next_task(self, provider_ids: list[str], task_types: list[str]) -> dict[str,
142142
return r
143143
return {}
144144

145+
def next_task_batch(
146+
self, provider_ids: list[str], task_types: list[str], number_of_tasks: int
147+
) -> dict[str, typing.Any]:
148+
"""Get the next n task processing tasks from Nextcloud.
149+
150+
Available starting with Nextcloud 33
151+
Returns: {tasks: [{task: Task, provider: string}], has_more: bool}
152+
"""
153+
with contextlib.suppress(NextcloudException):
154+
if r := self._session.ocs(
155+
"GET",
156+
"/ocs/v2.php/taskprocessing/tasks_provider/next_batch",
157+
json={"providerIds": provider_ids, "taskTypeIds": task_types, "numberOfTasks": number_of_tasks},
158+
):
159+
return r
160+
return {"tasks": [], "has_more": False}
161+
145162
def set_progress(self, task_id: int, progress: float) -> dict[str, typing.Any]:
146163
"""Report new progress value of the task to Nextcloud. Progress should be in range from 0.0 to 100.0."""
147164
with contextlib.suppress(NextcloudException):
@@ -220,6 +237,23 @@ async def next_task(self, provider_ids: list[str], task_types: list[str]) -> dic
220237
return r
221238
return {}
222239

240+
async def next_task_batch(
241+
self, provider_ids: list[str], task_types: list[str], number_of_tasks: int
242+
) -> dict[str, typing.Any]:
243+
"""Get the next n task processing tasks from Nextcloud.
244+
245+
Available starting with Nextcloud 33
246+
Returns: {tasks: [{task: Task, provider: string}], has_more: bool}
247+
"""
248+
with contextlib.suppress(NextcloudException):
249+
if r := await self._session.ocs(
250+
"GET",
251+
"/ocs/v2.php/taskprocessing/tasks_provider/next_batch",
252+
json={"providerIds": provider_ids, "taskTypeIds": task_types, "numberOfTasks": number_of_tasks},
253+
):
254+
return r
255+
return {"tasks": [], "has_more": False}
256+
223257
async def set_progress(self, task_id: int, progress: float) -> dict[str, typing.Any]:
224258
"""Report new progress value of the task to Nextcloud. Progress should be in range from 0.0 to 100.0."""
225259
with contextlib.suppress(NextcloudException):

0 commit comments

Comments
 (0)