@@ -23,6 +23,10 @@ fastapi's handler function.
23
23
I have a script called ` test_script.py ` so my app can be found at ` test_script:app ` .
24
24
We use strings to resolve application to bypass circular imports.
25
25
26
+ Also, as you can see, we use ` TaskiqDepends ` for Request. That's because
27
+ taskiq dependency resolver must know that this type must be injected. FastAPI disallow
28
+ Depends for Request type. That's why we use ` TaskiqDepends ` .
29
+
26
30
``` python
27
31
from fastapi import FastAPI, Request
28
32
from pydantic import BaseModel
@@ -73,6 +77,8 @@ async def app_shutdown():
73
77
taskiq_fastapi.init(broker, " test_script:app" )
74
78
75
79
80
+ # We use TaskiqDepends here, becuase if we use FastAPIDepends fastapi
81
+ # initilization will fail.
76
82
def get_redis_pool (request : Request = TaskiqDepends()) -> ConnectionPool:
77
83
return request.app.state.redis_pool
78
84
@@ -81,6 +87,9 @@ def get_redis_pool(request: Request = TaskiqDepends()) -> ConnectionPool:
81
87
async def my_redis_task (
82
88
key : str ,
83
89
val : str ,
90
+ # Here we depend using TaskiqDepends.
91
+ # Please use TaskiqDepends for all tasks to be resolved correctly.
92
+ # Or dependencies won't be injected.
84
93
pool : ConnectionPool = TaskiqDepends(get_redis_pool),
85
94
):
86
95
async with Redis(connection_pool = pool) as redis:
0 commit comments