-
Notifications
You must be signed in to change notification settings - Fork 176
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: support only uvicorn ASGI Runner (#1965)
* fix: support only uvicorn ASGI Runner * docs: generate API References * remove unused "type: ignore" --------- Co-authored-by: Sehat1137 <edox1j2n@duck.com> Co-authored-by: Sehat1137 <Sehat1137@users.noreply.github.com>
- Loading branch information
1 parent
777794e
commit cea4452
Showing
7 changed files
with
187 additions
and
50 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
11 changes: 11 additions & 0 deletions
11
docs/docs/en/api/faststream/asgi/app/cast_uvicorn_params.md
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,11 @@ | ||
--- | ||
# 0.5 - API | ||
# 2 - Release | ||
# 3 - Contributing | ||
# 5 - Template Page | ||
# 10 - Default | ||
search: | ||
boost: 0.5 | ||
--- | ||
|
||
::: faststream.asgi.app.cast_uvicorn_params |
11 changes: 11 additions & 0 deletions
11
docs/docs/en/api/faststream/cli/supervisors/asgi_multiprocess/ASGIMultiprocess.md
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,11 @@ | ||
--- | ||
# 0.5 - API | ||
# 2 - Release | ||
# 3 - Contributing | ||
# 5 - Template Page | ||
# 10 - Default | ||
search: | ||
boost: 0.5 | ||
--- | ||
|
||
::: faststream.cli.supervisors.asgi_multiprocess.ASGIMultiprocess |
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,38 @@ | ||
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