From 5af01d6c0d6668a40ef7f844da3d894d82b59fb3 Mon Sep 17 00:00:00 2001 From: alex-stoica Date: Sat, 15 Jun 2024 20:37:44 +0300 Subject: [PATCH] Enhance deploy_utils.py to support async execution using run_in_threadpool --- src/hayhooks/server/utils/deploy_utils.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/hayhooks/server/utils/deploy_utils.py b/src/hayhooks/server/utils/deploy_utils.py index a2b4119..9a5d762 100644 --- a/src/hayhooks/server/utils/deploy_utils.py +++ b/src/hayhooks/server/utils/deploy_utils.py @@ -1,6 +1,6 @@ from fastapi import HTTPException from fastapi.responses import JSONResponse - +from fastapi.concurrency import run_in_threadpool from hayhooks.server.pipelines import registry from hayhooks.server.pipelines.models import ( @@ -10,7 +10,6 @@ convert_component_output, ) - def deploy_pipeline_def(app, pipeline_def: PipelineDefinition): try: pipe = registry.add(pipeline_def.name, pipeline_def.source_code) @@ -24,7 +23,7 @@ def deploy_pipeline_def(app, pipeline_def: PipelineDefinition): # the endpoint handler. We have to ignore the type here to make FastAPI happy while # silencing static type checkers (that would have good reasons to trigger!). async def pipeline_run(pipeline_run_req: PipelineRunRequest) -> JSONResponse: # type: ignore - result = pipe.run(data=pipeline_run_req.dict()) + result = await run_in_threadpool(pipe.run, data=pipeline_run_req.dict()) final_output = {} for component_name, output in result.items(): final_output[component_name] = convert_component_output(output)