From c77caaaa9d0530507303233601b58a8a5b594724 Mon Sep 17 00:00:00 2001 From: Marcel Klehr Date: Mon, 20 Oct 2025 13:06:30 +0200 Subject: [PATCH 1/2] feat(TaskProcessing): Add trigger_handler to set_handlers() Signed-off-by: Marcel Klehr --- nc_py_api/ex_app/integration_fastapi.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/nc_py_api/ex_app/integration_fastapi.py b/nc_py_api/ex_app/integration_fastapi.py index 19c81c77..0bc10456 100644 --- a/nc_py_api/ex_app/integration_fastapi.py +++ b/nc_py_api/ex_app/integration_fastapi.py @@ -61,6 +61,7 @@ def set_handlers( default_init: bool = True, models_to_fetch: dict[str, dict] | None = None, map_app_static: bool = True, + trigger_handler: typing.Callable[[str], typing.Awaitable[None] | None] | None = None, ): """Defines handlers for the application. @@ -93,6 +94,8 @@ def set_handlers( :param map_app_static: Should be folders ``js``, ``css``, ``l10n``, ``img`` automatically mounted in FastAPI or not. .. note:: First, presence of these directories in the current working dir is checked, then one directory higher. + + :param trigger_handler: callback that is called for task processing `trigger` events with the id of the provider. """ if models_to_fetch is not None and default_init is False: raise ValueError("`models_to_fetch` can be defined only with `default_init`=True.") @@ -125,6 +128,21 @@ async def init_callback(b_tasks: BackgroundTasks, nc: typing.Annotated[Nextcloud if map_app_static: __map_app_static_folders(fast_api_app) + if trigger_handler: + if asyncio.iscoroutinefunction(trigger_handler): + + @fast_api_app.post("/trigger") + async def trigger_callback(providerId: str):# pylint: disable=invalid-name + await trigger_handler(providerId) + return JSONResponse(content={}) + + else: + + @fast_api_app.post("/trigger") + def trigger_callback(providerId: str):# pylint: disable=invalid-name + trigger_handler(providerId) + return JSONResponse(content={}) + def __map_app_static_folders(fast_api_app: FastAPI): """Function to mount all necessary static folders to FastAPI.""" From b2c157bc347d3bffa45c9f877b34b13e9379f531 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 21 Oct 2025 06:59:36 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- nc_py_api/ex_app/integration_fastapi.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nc_py_api/ex_app/integration_fastapi.py b/nc_py_api/ex_app/integration_fastapi.py index 0bc10456..552fc5fa 100644 --- a/nc_py_api/ex_app/integration_fastapi.py +++ b/nc_py_api/ex_app/integration_fastapi.py @@ -132,14 +132,14 @@ async def init_callback(b_tasks: BackgroundTasks, nc: typing.Annotated[Nextcloud if asyncio.iscoroutinefunction(trigger_handler): @fast_api_app.post("/trigger") - async def trigger_callback(providerId: str):# pylint: disable=invalid-name + async def trigger_callback(providerId: str): # pylint: disable=invalid-name await trigger_handler(providerId) return JSONResponse(content={}) else: @fast_api_app.post("/trigger") - def trigger_callback(providerId: str):# pylint: disable=invalid-name + def trigger_callback(providerId: str): # pylint: disable=invalid-name trigger_handler(providerId) return JSONResponse(content={})