c56bef871b
Sync docs with Docusaurus / sync (push) Waiting to run
Tests / Check if changed (push) Waiting to run
Tests / format (push) Blocked by required conditions
Tests / check-imports (push) Blocked by required conditions
Tests / Unit / macos-latest (push) Blocked by required conditions
Tests / Unit / ubuntu-latest (push) Blocked by required conditions
Tests / Unit / windows-latest (push) Blocked by required conditions
Tests / mypy (push) Blocked by required conditions
Tests / Integration / ubuntu-latest (push) Blocked by required conditions
Tests / Integration / macos-latest (push) Blocked by required conditions
Tests / Integration / windows-latest (push) Blocked by required conditions
Tests / notify-slack-on-failure (push) Blocked by required conditions
Tests / Mark tests as completed (push) Blocked by required conditions
Docker image release / Build base image (push) Waiting to run
CodeQL / Analyze (python) (push) Has been cancelled
Update Platform Components Table / update (push) Has been cancelled
36 lines
1.3 KiB
Python
36 lines
1.3 KiB
Python
# SPDX-FileCopyrightText: 2022-present deepset GmbH <info@deepset.ai>
|
|
#
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
import asyncio
|
|
from typing import Any
|
|
|
|
from haystack import logging
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
async def _execute_component_async(component_instance: Any, **kwargs: Any) -> dict[str, Any]:
|
|
"""
|
|
Run a component asynchronously, preferring its `run_async` method when implemented.
|
|
|
|
If the component does not implement `run_async`, its synchronous `run` method is executed in a thread
|
|
to avoid blocking the event loop.
|
|
|
|
:param component_instance: The component to run. Any object exposing a `run` method and optionally a
|
|
`run_async` coroutine method.
|
|
:param kwargs: Keyword arguments passed to the component's `run_async` or `run` method.
|
|
:returns:
|
|
The component's output dictionary.
|
|
"""
|
|
run_async = getattr(component_instance, "run_async", None)
|
|
if callable(run_async):
|
|
return await run_async(**kwargs)
|
|
|
|
logger.debug(
|
|
"{component_type} does not implement 'run_async'. Running the synchronous 'run' method in a thread "
|
|
"to avoid blocking the event loop.",
|
|
component_type=type(component_instance).__name__,
|
|
)
|
|
return await asyncio.to_thread(component_instance.run, **kwargs)
|