initial
This commit is contained in:
22
app/routers/take.py
Normal file
22
app/routers/take.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import fastapi
|
||||
import pydantic
|
||||
import typing
|
||||
|
||||
from app.storage.mongo import tasks
|
||||
|
||||
|
||||
router = fastapi.APIRouter()
|
||||
|
||||
|
||||
class Response(pydantic.BaseModel):
|
||||
id: str
|
||||
attempt: int
|
||||
payload: dict
|
||||
|
||||
|
||||
@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)
|
||||
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