Skip to content

update docstrings and typing #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions taskiq_fastapi/initializator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@
from taskiq import AsyncBroker, TaskiqEvents, TaskiqState
from taskiq.cli.utils import import_object

PathOrAppOrFactory = Union[str, FastAPI, Callable[[], FastAPI]]


def startup_event_generator(
broker: AsyncBroker,
app_or_path: Union[str, FastAPI],
app_or_path: PathOrAppOrFactory,
) -> Callable[[TaskiqState], Awaitable[None]]:
"""
Generate shutdown event.
Generate startup event handler.

This function takes FastAPI application path
and runs startup event on broker's startup.

:param broker: current broker.
:param app_path: fastapi application path.
:param app_or_path: application path or fastapi instance or callable that creates fastapi app instance.
:returns: startup handler.
"""

Expand Down Expand Up @@ -48,7 +50,7 @@ def shutdown_event_generator(
broker: AsyncBroker,
) -> Callable[[TaskiqState], Awaitable[None]]:
"""
Generate shutdown event.
Generate shutdown event handler.

This function takes FastAPI application
and runs shutdown event on broker's shutdown.
Expand All @@ -66,7 +68,7 @@ async def shutdown(state: TaskiqState) -> None:
return shutdown


def init(broker: AsyncBroker, app_or_path: Union[str, FastAPI]) -> None:
def init(broker: AsyncBroker, app_or_path: PathOrAppOrFactory) -> None:
"""
Add taskiq startup events.

Expand All @@ -78,7 +80,7 @@ def init(broker: AsyncBroker, app_or_path: Union[str, FastAPI]) -> None:
startup events will run.

:param broker: current broker to use.
:param app_path: path to fastapi application.
:param app_or_path: application path or fastapi instance or callable that creates fastapi app instance.
"""
broker.add_event_handler(
TaskiqEvents.WORKER_STARTUP,
Expand All @@ -102,7 +104,7 @@ def populate_dependency_context(
This function injects the Request and HTTPConnection
into the broker's dependency context.

It may be need to be called manually if you are using InMemoryBroker.
It may be needed to be called manually if you are using InMemoryBroker.

:param broker: current broker to use.
:param app: current application.
Expand Down