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 or callable that creates fastapi app instance .
2325 :returns: startup handler.
2426 """
2527
@@ -50,7 +52,7 @@ def shutdown_event_generator(
5052 broker : AsyncBroker ,
5153) -> Callable [[TaskiqState ], Awaitable [None ]]:
5254 """
53- Generate shutdown event.
55+ Generate shutdown event handler .
5456
5557 This function takes FastAPI application
5658 and runs shutdown event on broker's shutdown.
@@ -68,7 +70,7 @@ async def shutdown(state: TaskiqState) -> None:
6870 return shutdown
6971
7072
71- def init (broker : AsyncBroker , app_or_path : str | FastAPI ) -> None :
73+ def init (broker : AsyncBroker , app_or_path : PathOrAppOrFactory ) -> None :
7274 """
7375 Add taskiq startup events.
7476
@@ -80,7 +82,7 @@ def init(broker: AsyncBroker, app_or_path: str | FastAPI) -> None:
8082 startup events will run.
8183
8284 :param broker: current broker to use.
83- :param app_path: path to fastapi application .
85+ :param app_or_path: application path or fastapi instance or callable that creates fastapi app instance .
8486 """
8587 broker .add_event_handler (
8688 TaskiqEvents .WORKER_STARTUP ,
@@ -104,7 +106,7 @@ def populate_dependency_context(
104106 This function injects the Request and HTTPConnection
105107 into the broker's dependency context.
106108
107- It may be need to be called manually if you are using InMemoryBroker.
109+ It may be needed to be called manually if you are using InMemoryBroker.
108110
109111 :param broker: current broker to use.
110112 :param app: current application.
0 commit comments