5
5
from taskiq import AsyncBroker , TaskiqEvents , TaskiqState
6
6
from taskiq .cli .utils import import_object
7
7
8
+ PathOrAppOrFactory = Union [str , FastAPI , Callable [[], FastAPI ]]
9
+
8
10
9
11
def startup_event_generator (
10
12
broker : AsyncBroker ,
11
- app_or_path : Union [ str , FastAPI ] ,
13
+ app_or_path : PathOrAppOrFactory ,
12
14
) -> Callable [[TaskiqState ], Awaitable [None ]]:
13
15
"""
14
- Generate shutdown event.
16
+ Generate startup event handler .
15
17
16
18
This function takes FastAPI application path
17
19
and runs startup event on broker's startup.
18
20
19
21
:param broker: current broker.
20
- :param app_path: fastapi application path.
22
+ :param app_or_path: application path or fastapi instance or callable that creates fastapi app instance .
21
23
:returns: startup handler.
22
24
"""
23
25
@@ -48,7 +50,7 @@ def shutdown_event_generator(
48
50
broker : AsyncBroker ,
49
51
) -> Callable [[TaskiqState ], Awaitable [None ]]:
50
52
"""
51
- Generate shutdown event.
53
+ Generate shutdown event handler .
52
54
53
55
This function takes FastAPI application
54
56
and runs shutdown event on broker's shutdown.
@@ -66,7 +68,7 @@ async def shutdown(state: TaskiqState) -> None:
66
68
return shutdown
67
69
68
70
69
- def init (broker : AsyncBroker , app_or_path : Union [ str , FastAPI ] ) -> None :
71
+ def init (broker : AsyncBroker , app_or_path : PathOrAppOrFactory ) -> None :
70
72
"""
71
73
Add taskiq startup events.
72
74
@@ -78,7 +80,7 @@ def init(broker: AsyncBroker, app_or_path: Union[str, FastAPI]) -> None:
78
80
startup events will run.
79
81
80
82
:param broker: current broker to use.
81
- :param app_path: path to fastapi application .
83
+ :param app_or_path: application path or fastapi instance or callable that creates fastapi app instance .
82
84
"""
83
85
broker .add_event_handler (
84
86
TaskiqEvents .WORKER_STARTUP ,
@@ -102,7 +104,7 @@ def populate_dependency_context(
102
104
This function injects the Request and HTTPConnection
103
105
into the broker's dependency context.
104
106
105
- It may be need to be called manually if you are using InMemoryBroker.
107
+ It may be needed to be called manually if you are using InMemoryBroker.
106
108
107
109
:param broker: current broker to use.
108
110
:param app: current application.
0 commit comments