From 919cf5c0414f2f11eb8012f451fed7a8f582b7ad Mon Sep 17 00:00:00 2001 From: Michele Dolfi <97102151+dolfim-ibm@users.noreply.github.com> Date: Wed, 30 Apr 2025 12:30:11 +0200 Subject: [PATCH] fix: expose max wait time in sync endpoints (#164) Signed-off-by: Michele Dolfi --- docling_serve/app.py | 9 +++++---- docling_serve/settings.py | 2 ++ docs/configuration.md | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/docling_serve/app.py b/docling_serve/app.py index f35014b..07a3cb7 100644 --- a/docling_serve/app.py +++ b/docling_serve/app.py @@ -251,7 +251,6 @@ def create_app(): # noqa: C901 async def _wait_task_complete( orchestrator: BaseAsyncOrchestrator, task_id: str ) -> bool: - MAX_WAIT = 120 start_time = time.monotonic() while True: task = await orchestrator.task_status(task_id=task_id) @@ -259,7 +258,7 @@ def create_app(): # noqa: C901 return True await asyncio.sleep(5) elapsed_time = time.monotonic() - start_time - if elapsed_time > MAX_WAIT: + if elapsed_time > docling_serve_settings.max_sync_wait: return False ############################# @@ -310,7 +309,8 @@ def create_app(): # noqa: C901 if not success: # TODO: abort task! return HTTPException( - status_code=504, detail="Conversion is taking too long." + status_code=504, + detail=f"Conversion is taking too long. The maximum wait time is configure as DOCLING_SERVE_MAX_SYNC_WAIT={docling_serve_settings.max_sync_wait}.", ) result = await orchestrator.task_result( @@ -351,7 +351,8 @@ def create_app(): # noqa: C901 if not success: # TODO: abort task! return HTTPException( - status_code=504, detail="Conversion is taking too long." + status_code=504, + detail=f"Conversion is taking too long. The maximum wait time is configure as DOCLING_SERVE_MAX_SYNC_WAIT={docling_serve_settings.max_sync_wait}.", ) result = await orchestrator.task_result( diff --git a/docling_serve/settings.py b/docling_serve/settings.py index ebc120c..6c06e4d 100644 --- a/docling_serve/settings.py +++ b/docling_serve/settings.py @@ -48,6 +48,8 @@ class DoclingServeSettings(BaseSettings): max_num_pages: int = sys.maxsize max_file_size: int = sys.maxsize + max_sync_wait: int = 120 # 2 minutes + cors_origins: list[str] = ["*"] cors_methods: list[str] = ["*"] cors_headers: list[str] = ["*"] diff --git a/docs/configuration.md b/docs/configuration.md index ed3c049..cf594db 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -45,6 +45,7 @@ THe following table describes the options to configure the Docling Serve app. | | `DOCLING_SERVE_MAX_DOCUMENT_TIMEOUT` | `604800` (7 days) | The maximum time for processing a document. | | | `DOCLING_SERVE_MAX_NUM_PAGES` | | The maximum number of pages for a document to be processed. | | | `DOCLING_SERVE_MAX_FILE_SIZE` | | The maximum file size for a document to be processed. | +| | `DOCLING_SERVE_MAX_SYNC_WAIT` | `120` | Max number of seconds a synchronous endpoint is waiting for the task completion. | | | `DOCLING_SERVE_OPTIONS_CACHE_SIZE` | `2` | How many DocumentConveter objects (including their loaded models) to keep in the cache. | | | `DOCLING_SERVE_CORS_ORIGINS` | `["*"]` | A list of origins that should be permitted to make cross-origin requests. | | | `DOCLING_SERVE_CORS_METHODS` | `["*"]` | A list of HTTP methods that should be allowed for cross-origin requests. |