import fastapi import pydantic import typing from app.storage.mongo import tasks DEFAULT_RETRY_AFTER = 0.2 router = fastapi.APIRouter() class Task(pydantic.BaseModel): id: str attempt: int payload: dict class Response(pydantic.BaseModel): task: Task|None @router.get('/api/v1/take') async def execute(queue: typing.Annotated[str, fastapi.Header()]) -> Response: try: task = await tasks.take_task(queue) except Exception as e: print('GOT ERROR', e) return Response(task=None) if not task: return Response(task=None) return Response(task=Task(id=str(task._id), attempt=task.attempts, payload=task.payload))