redis
All checks were successful
Deploy Dev / Build (pull_request) Successful in 6s
Deploy Dev / Push (pull_request) Successful in 8s
Deploy Dev / Deploy dev (pull_request) Successful in 5s

This commit is contained in:
2024-11-25 00:27:40 +03:00
parent be7bc1ef2c
commit a328d6feb2
7 changed files with 32 additions and 1 deletions

View File

@@ -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)