commit
875294bdd7
@ -8,4 +8,6 @@ RUN pip install -r requirements.txt
|
||||
|
||||
COPY . .
|
||||
|
||||
ENV PYTHONUNBUFFERED 1
|
||||
|
||||
ENTRYPOINT ["python", "main.py"]
|
||||
|
@ -1,5 +1,3 @@
|
||||
import asyncio
|
||||
import collections
|
||||
import fastapi
|
||||
import pydantic
|
||||
import typing
|
||||
@ -9,7 +7,6 @@ from app.storage.mongo import tasks
|
||||
|
||||
|
||||
DEFAULT_RETRY_AFTER = 0.2
|
||||
locks = collections.defaultdict(asyncio.Lock)
|
||||
router = fastapi.APIRouter()
|
||||
|
||||
|
||||
@ -23,10 +20,13 @@ class Response(pydantic.BaseModel):
|
||||
task: Task|None
|
||||
|
||||
|
||||
@router.get('/api/v1/take', responses={500: {'detail': 'Internal server error'}})
|
||||
@router.get('/api/v1/take')
|
||||
async def execute(queue: typing.Annotated[str, fastapi.Header()]) -> Response:
|
||||
async with locks[queue]:
|
||||
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)
|
||||
# retry_after_config = configurator.get_config('retry_after')
|
||||
|
Loading…
Reference in New Issue
Block a user