You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Also you want to call startup of your brokers somewhere.
83
83
84
+
::: tabs
85
+
86
+
@tab Lifespan (Recommended)
87
+
88
+
```python
89
+
from contextlib import asynccontextmanager
90
+
from fastapi import FastAPI
91
+
from your_project.taskiq import broker
92
+
93
+
94
+
@asynccontextmanager
95
+
asyncdeflifespan(app: FastAPI):
96
+
# Startup
97
+
ifnot broker.is_worker_process:
98
+
await broker.startup()
99
+
yield
100
+
# Shutdown
101
+
ifnot broker.is_worker_process:
102
+
await broker.shutdown()
103
+
104
+
105
+
app = FastAPI(lifespan=lifespan)
106
+
```
107
+
108
+
@tab on_event (Deprecated)
109
+
84
110
```python
85
111
from fastapi import FastAPI
86
112
from your_project.taskiq import broker
@@ -101,6 +127,8 @@ async def app_shutdown():
101
127
102
128
```
103
129
130
+
:::
131
+
104
132
And that's it. Now you can use your taskiq tasks with functions and classes that depend on FastAPI dependencies. You can find bigger examples in the [examples repo](https://github.com/taskiq-python/examples/).
0 commit comments