-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
sehat1137
committed
Nov 30, 2024
1 parent
48b7304
commit b3086f5
Showing
4 changed files
with
75 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import inspect | ||
from typing import Dict, Tuple | ||
|
||
from faststream.asgi.app import cast_uvicorn_params | ||
|
||
|
||
class ASGIMultiprocess: | ||
def __init__(self, target: str, args: Tuple[str, Dict[str, str], bool, int], workers: int) -> None: | ||
_, uvicorn_kwargs, is_factory, log_level = args | ||
self._target = target | ||
self._uvicorn_kwargs = cast_uvicorn_params(uvicorn_kwargs or {}) | ||
self._workers = workers | ||
self._is_factory = is_factory | ||
self._log_level = log_level | ||
|
||
def run(self) -> None: | ||
try: | ||
import uvicorn | ||
except ImportError as e: | ||
raise RuntimeError( | ||
"You need uvicorn to run FastStream ASGI App via CLI. pip install uvicorn" | ||
) from e | ||
|
||
uvicorn_params = set(inspect.signature(uvicorn.run).parameters.keys()) | ||
|
||
uvicorn.run( | ||
self._target, | ||
factory=self._is_factory, | ||
workers=self._workers, | ||
log_level=self._log_level, | ||
**{key: v for key, v in self._uvicorn_kwargs.items() if key in uvicorn_params} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters