Compare commits

..

No commits in common. "af1bd07d8831ab3258c8009b41079bc2e8e318f4" and "407a2222b46a6eacd940af425c1ddc15555feea5" have entirely different histories.

2 changed files with 4 additions and 3 deletions

View File

@ -25,5 +25,5 @@ class Response(pydantic.BaseModel):
async def execute(queue: typing.Annotated[str, fastapi.Header()]) -> Response:
task = await tasks.take_task(queue)
if not task:
return Response(task=None)
return Response(task=Task(id=str(task._id), attempt=task.attempts, payload=task.payload))
raise fastapi.HTTPException(404)
return Response(id=str(task._id), attempt=task.attempts, payload=task.payload, task=Task(id=str(task._id), attempt=task.attempts, payload=task.payload))

View File

@ -1,6 +1,7 @@
import bson
import datetime
import pydantic
import typing
from app.storage.mongo import database
from app.utils import time
@ -26,7 +27,7 @@ async def add_task(task: Task) -> str:
return result.inserted_id
async def take_task(queue: str) -> Task|None:
async def take_task(queue: str) -> typing.Optional[Task]:
now = time.now()
async for raw_task in collection.find({'queue': queue, 'available_from': {'$lte': now}}):
task = Task.model_validate(raw_task)