Skip to content

Commit ca986c2

Browse files
committed
Updated README.md.
Signed-off-by: Pavel Kirilin <[email protected]>
1 parent 9232eac commit ca986c2

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ fastapi's handler function.
2323
I have a script called `test_script.py` so my app can be found at `test_script:app`.
2424
We use strings to resolve application to bypass circular imports.
2525

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+
2630
```python
2731
from fastapi import FastAPI, Request
2832
from pydantic import BaseModel
@@ -73,6 +77,8 @@ async def app_shutdown():
7377
taskiq_fastapi.init(broker, "test_script:app")
7478

7579

80+
# We use TaskiqDepends here, becuase if we use FastAPIDepends fastapi
81+
# initilization will fail.
7682
def get_redis_pool(request: Request = TaskiqDepends()) -> ConnectionPool:
7783
return request.app.state.redis_pool
7884

@@ -81,6 +87,9 @@ def get_redis_pool(request: Request = TaskiqDepends()) -> ConnectionPool:
8187
async def my_redis_task(
8288
key: str,
8389
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.
8493
pool: ConnectionPool = TaskiqDepends(get_redis_pool),
8594
):
8695
async with Redis(connection_pool=pool) as redis:

0 commit comments

Comments
 (0)