fix #13
@ -3,7 +3,7 @@ import pydantic
|
|||||||
import typing
|
import typing
|
||||||
|
|
||||||
from app.storage.mongo import tasks
|
from app.storage.mongo import tasks
|
||||||
from app.storage.redis import lock
|
from app.storage import redis
|
||||||
|
|
||||||
|
|
||||||
router = fastapi.APIRouter()
|
router = fastapi.APIRouter()
|
||||||
@ -17,7 +17,7 @@ class Response(pydantic.BaseModel):
|
|||||||
|
|
||||||
@router.get('/api/v1/take', responses={404: {'description': 'Not found'}})
|
@router.get('/api/v1/take', responses={404: {'description': 'Not found'}})
|
||||||
async def execute(queue: typing.Annotated[str, fastapi.Header()]) -> Response:
|
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)
|
task = await tasks.take_task(queue)
|
||||||
if not task:
|
if not task:
|
||||||
raise fastapi.HTTPException(404)
|
raise fastapi.HTTPException(404)
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import asyncio
|
|
||||||
import bson
|
import bson
|
||||||
import datetime
|
import datetime
|
||||||
import pydantic
|
import pydantic
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import os
|
import os
|
||||||
import redis.asyncio
|
import redis.asyncio as connection
|
||||||
|
|
||||||
|
|
||||||
REDIS_HOST = os.getenv('REDIS_HOST', 'localhost')
|
REDIS_HOST = os.getenv('REDIS_HOST', 'localhost')
|
||||||
@ -11,5 +11,5 @@ else:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
pool = redis.asyncio.ConnectionPool.from_url(URL)
|
pool = connection.from_url(URL)
|
||||||
database = redis.Redis.from_pool(pool)
|
database = connection.Redis.from_pool(pool)
|
||||||
|
@ -1,8 +0,0 @@
|
|||||||
import contextlib
|
|
||||||
|
|
||||||
from app.storage import redis
|
|
||||||
|
|
||||||
|
|
||||||
@contextlib.contextmanager
|
|
||||||
def acquire(lock_name: str):
|
|
||||||
return redis.database.lock(lock_name)
|
|
Loading…
Reference in New Issue
Block a user