redis
This commit is contained in:
@@ -3,6 +3,7 @@ import pydantic
|
||||
import typing
|
||||
|
||||
from app.storage.mongo import tasks
|
||||
from app.storage.redis import lock
|
||||
|
||||
|
||||
router = fastapi.APIRouter()
|
||||
@@ -16,7 +17,8 @@ class Response(pydantic.BaseModel):
|
||||
|
||||
@router.get('/api/v1/take', responses={404: {'description': 'Not found'}})
|
||||
async def execute(queue: typing.Annotated[str, fastapi.Header()]) -> Response:
|
||||
task = await tasks.take_task(queue)
|
||||
async with lock.acquire(queue):
|
||||
task = await tasks.take_task(queue)
|
||||
if not task:
|
||||
raise fastapi.HTTPException(404)
|
||||
return Response(id=str(task._id), attempt=task.attempts, payload=task.payload)
|
||||
|
||||
Reference in New Issue
Block a user