diff --git a/taskiq_fastapi/initializator.py b/taskiq_fastapi/initializator.py index f31a6f0..dc18fef 100644 --- a/taskiq_fastapi/initializator.py +++ b/taskiq_fastapi/initializator.py @@ -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. """ @@ -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. @@ -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. @@ -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, @@ -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.