Skip to content

Commit

Permalink
Merge branch 'release/0.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
s3rius committed Mar 26, 2023
2 parents e1daef5 + 7cce6f1 commit 2e60447
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ fastapi's handler function.
I have a script called `test_script.py` so my app can be found at `test_script:app`.
We use strings to resolve application to bypass circular imports.

Also, as you can see, we use `TaskiqDepends` for Request. That's because
taskiq dependency resolver must know that this type must be injected. FastAPI disallow
Depends for Request type. That's why we use `TaskiqDepends`.

```python
from fastapi import FastAPI, Request
from pydantic import BaseModel
Expand Down Expand Up @@ -73,6 +77,8 @@ async def app_shutdown():
taskiq_fastapi.init(broker, "test_script:app")


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

Expand All @@ -81,6 +87,9 @@ def get_redis_pool(request: Request = TaskiqDepends()) -> ConnectionPool:
async def my_redis_task(
key: str,
val: str,
# Here we depend using TaskiqDepends.
# Please use TaskiqDepends for all tasks to be resolved correctly.
# Or dependencies won't be injected.
pool: ConnectionPool = TaskiqDepends(get_redis_pool),
):
async with Redis(connection_pool=pool) as redis:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "taskiq-fastapi"
description = "FastAPI integration for taskiq"
authors = ["Taskiq team <[email protected]>"]
maintainers = ["Taskiq team <[email protected]>"]
version = "0.1.0"
version = "0.1.1"
readme = "README.md"
license = "LICENSE"
classifiers = [
Expand Down

0 comments on commit 2e60447

Please sign in to comment.