fix
This commit is contained in:
@@ -5,8 +5,10 @@ import pydantic
|
||||
import typing
|
||||
|
||||
from app.storage.mongo import tasks
|
||||
from app.utils.configurator import configurator
|
||||
|
||||
|
||||
DEFAULT_RETRY_AFTER = 0.2
|
||||
locks = collections.defaultdict(asyncio.Lock)
|
||||
router = fastapi.APIRouter()
|
||||
|
||||
@@ -19,12 +21,15 @@ class Task(pydantic.BaseModel):
|
||||
|
||||
class Response(pydantic.BaseModel):
|
||||
task: Task|None
|
||||
retry_after: float
|
||||
|
||||
|
||||
@router.get('/api/v1/take', responses={404: {'description': 'Not found'}})
|
||||
@router.get('/api/v1/take')
|
||||
async def execute(queue: typing.Annotated[str, fastapi.Header()]) -> Response:
|
||||
async with locks[queue]:
|
||||
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))
|
||||
retry_after_config = configurator.get_config('retry_after')
|
||||
retry_after = retry_after_config.get(queue) or retry_after_config.get('default') or DEFAULT_RETRY_AFTER
|
||||
return Response(task=Task(id=str(task._id), attempt=task.attempts, payload=task.payload), retry_after=retry_after)
|
||||
|
||||
Reference in New Issue
Block a user