fix #18
@ -25,5 +25,5 @@ class Response(pydantic.BaseModel):
|
|||||||
async def execute(queue: typing.Annotated[str, fastapi.Header()]) -> Response:
|
async def execute(queue: typing.Annotated[str, fastapi.Header()]) -> Response:
|
||||||
task = await tasks.take_task(queue)
|
task = await tasks.take_task(queue)
|
||||||
if not task:
|
if not task:
|
||||||
raise fastapi.HTTPException(404)
|
return Response(task=None)
|
||||||
return Response(id=str(task._id), attempt=task.attempts, payload=task.payload, task=Task(id=str(task._id), attempt=task.attempts, payload=task.payload))
|
return Response(task=Task(id=str(task._id), attempt=task.attempts, payload=task.payload))
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import bson
|
import bson
|
||||||
import datetime
|
import datetime
|
||||||
import pydantic
|
import pydantic
|
||||||
import typing
|
|
||||||
|
|
||||||
from app.storage.mongo import database
|
from app.storage.mongo import database
|
||||||
from app.utils import time
|
from app.utils import time
|
||||||
@ -27,7 +26,7 @@ async def add_task(task: Task) -> str:
|
|||||||
return result.inserted_id
|
return result.inserted_id
|
||||||
|
|
||||||
|
|
||||||
async def take_task(queue: str) -> typing.Optional[Task]:
|
async def take_task(queue: str) -> Task|None:
|
||||||
now = time.now()
|
now = time.now()
|
||||||
async for raw_task in collection.find({'queue': queue, 'available_from': {'$lte': now}}):
|
async for raw_task in collection.find({'queue': queue, 'available_from': {'$lte': now}}):
|
||||||
task = Task.model_validate(raw_task)
|
task = Task.model_validate(raw_task)
|
||||||
|
Loading…
Reference in New Issue
Block a user