diff --git a/app/routers/take.py b/app/routers/take.py index a2abae1..34cddb4 100644 --- a/app/routers/take.py +++ b/app/routers/take.py @@ -3,7 +3,7 @@ import pydantic import typing from app.storage.mongo import tasks -from app.storage.redis import lock +from app.storage import redis router = fastapi.APIRouter() @@ -17,7 +17,7 @@ class Response(pydantic.BaseModel): @router.get('/api/v1/take', responses={404: {'description': 'Not found'}}) async def execute(queue: typing.Annotated[str, fastapi.Header()]) -> Response: - async with lock.acquire(queue): + async with redis.database.lock(queue): task = await tasks.take_task(queue) if not task: raise fastapi.HTTPException(404) diff --git a/app/storage/mongo/tasks.py b/app/storage/mongo/tasks.py index 0758760..e1b480a 100644 --- a/app/storage/mongo/tasks.py +++ b/app/storage/mongo/tasks.py @@ -1,4 +1,3 @@ -import asyncio import bson import datetime import pydantic diff --git a/app/storage/redis/__init__.py b/app/storage/redis/__init__.py index 417b2f5..3b59e59 100644 --- a/app/storage/redis/__init__.py +++ b/app/storage/redis/__init__.py @@ -1,5 +1,5 @@ import os -import redis.asyncio +import redis.asyncio as connection REDIS_HOST = os.getenv('REDIS_HOST', 'localhost') @@ -11,5 +11,5 @@ else: -pool = redis.asyncio.ConnectionPool.from_url(URL) -database = redis.Redis.from_pool(pool) +pool = connection.from_url(URL) +database = connection.Redis.from_pool(pool) diff --git a/app/storage/redis/lock.py b/app/storage/redis/lock.py deleted file mode 100644 index 5282a58..0000000 --- a/app/storage/redis/lock.py +++ /dev/null @@ -1,8 +0,0 @@ -import contextlib - -from app.storage import redis - - -@contextlib.contextmanager -def acquire(lock_name: str): - return redis.database.lock(lock_name)