Skip to content

Commit

Permalink
Enhance deploy_utils.py to support async execution using run_in_threa…
Browse files Browse the repository at this point in the history
…dpool
  • Loading branch information
alex-stoica committed Jun 15, 2024
1 parent 29aa909 commit 5af01d6
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions src/hayhooks/server/utils/deploy_utils.py
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 5af01d6

Please sign in to comment.