77from taskiq import AsyncBroker , TaskiqEvents , TaskiqState
88from taskiq .cli .utils import import_object
99
10+ PathOrAppOrFactory = str | FastAPI | Callable [[], FastAPI ]
11+
1012
1113def startup_event_generator (
1214 broker : AsyncBroker ,
13- app_or_path : str | FastAPI ,
15+ app_or_path : PathOrAppOrFactory ,
1416) -> Callable [[TaskiqState ], Awaitable [None ]]:
1517 """
16- Generate shutdown event.
18+ Generate startup event handler .
1719
1820 This function takes FastAPI application path
1921 and runs startup event on broker's startup.
2022
2123 :param broker: current broker.
22- :param app_path: fastapi application path.
24+ :param app_or_path: application path or fastapi instance
25+ or callable that creates fastapi app instance.
2326 :returns: startup handler.
2427 """
2528
@@ -50,7 +53,7 @@ def shutdown_event_generator(
5053 broker : AsyncBroker ,
5154) -> Callable [[TaskiqState ], Awaitable [None ]]:
5255 """
53- Generate shutdown event.
56+ Generate shutdown event handler .
5457
5558 This function takes FastAPI application
5659 and runs shutdown event on broker's shutdown.
@@ -68,7 +71,7 @@ async def shutdown(state: TaskiqState) -> None:
6871 return shutdown
6972
7073
71- def init (broker : AsyncBroker , app_or_path : str | FastAPI ) -> None :
74+ def init (broker : AsyncBroker , app_or_path : PathOrAppOrFactory ) -> None :
7275 """
7376 Add taskiq startup events.
7477
@@ -80,7 +83,8 @@ def init(broker: AsyncBroker, app_or_path: str | FastAPI) -> None:
8083 startup events will run.
8184
8285 :param broker: current broker to use.
83- :param app_path: path to fastapi application.
86+ :param app_or_path: application path or fastapi instance
87+ or callable that creates fastapi app instance.
8488 """
8589 broker .add_event_handler (
8690 TaskiqEvents .WORKER_STARTUP ,
@@ -104,7 +108,7 @@ def populate_dependency_context(
104108 This function injects the Request and HTTPConnection
105109 into the broker's dependency context.
106110
107- It may be need to be called manually if you are using InMemoryBroker.
111+ It may be needed to be called manually if you are using InMemoryBroker.
108112
109113 :param broker: current broker to use.
110114 :param app: current application.
0 commit comments