Compare commits

..

5 Commits

Author SHA1 Message Date
8ca8bf88c1 Merge pull request 'master' (#20) from master into prod
Reviewed-on: #20
2024-11-27 02:53:14 +03:00
f462477280 Merge pull request 'master' (#17) from master into prod
Reviewed-on: #17
2024-11-27 02:13:37 +03:00
8849a08930 Merge pull request 'fix' (#10) from master into prod
Reviewed-on: #10
2024-11-22 01:57:22 +03:00
e3c2f3dea0 Merge pull request 'master' (#9) from master into prod
Reviewed-on: #9
2024-11-22 01:20:39 +03:00
382ab2da25 Merge pull request 'master' (#7) from master into prod
Reviewed-on: #7
2024-11-17 13:28:04 +03:00
7 changed files with 5 additions and 43 deletions

BIN
.DS_Store vendored

Binary file not shown.

View File

@@ -7,9 +7,8 @@ services:
networks:
- queues-development
environment:
MONGO_HOST: "mongo.dev.chocomarsh.com"
MONGO_HOST: "mongo.develop.sprinthub.ru"
MONGO_PASSWORD: $MONGO_PASSWORD_DEV
STAGE: "development"
deploy:
mode: replicated
restart_policy:

View File

@@ -7,9 +7,8 @@ services:
networks:
- queues
environment:
MONGO_HOST: "mongo.chocomarsh.com"
MONGO_HOST: "mongo.sprinthub.ru"
MONGO_PASSWORD: $MONGO_PASSWORD_PROD
STAGE: "production"
deploy:
mode: replicated
restart_policy:

View File

@@ -8,6 +8,4 @@ RUN pip install -r requirements.txt
COPY . .
ENV PYTHONUNBUFFERED=1
ENTRYPOINT ["python", "main.py"]

View File

@@ -1,5 +1,3 @@
import asyncio
import collections
import fastapi
import pydantic
import typing
@@ -7,7 +5,6 @@ import typing
from app.storage.mongo import tasks
locks = collections.defaultdict(asyncio.Lock)
router = fastapi.APIRouter()
@@ -23,8 +20,7 @@ class Response(pydantic.BaseModel):
@router.get('/api/v1/take', responses={404: {'description': 'Not found'}})
async def execute(queue: typing.Annotated[str, fastapi.Header()]) -> Response:
async with locks[queue]:
task = await tasks.take_task(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))

10
main.py
View File

@@ -8,20 +8,14 @@ from app.routers import finish
from app.storage import mongo
app = fastapi.FastAPI(debug=True)
app = fastapi.FastAPI()
app.include_router(take.router)
app.include_router(put.router)
app.include_router(finish.router)
@app.exception_handler(Exception)
async def unicorn_exception_handler(request: fastapi.Request, exc: Exception):
return fastapi.JSONResponse(
status_code=500,
content={"message": f"Oops! {exc.name} did something. There goes a rainbow... {exc}"},
)
mongo.create_indexes()
if __name__ == '__main__':
uvicorn.run(app, host="0.0.0.0", port=1239)

View File

@@ -1,44 +1,20 @@
annotated-types==0.7.0
anyio==4.6.2.post1
APScheduler==3.10.4
certifi==2024.12.14
charset-normalizer==3.4.1
click==8.1.7
dnspython==2.7.0
email_validator==2.2.0
fastapi==0.115.4
fastapi-cli==0.0.7
h11==0.14.0
httpcore==1.0.7
httptools==0.6.4
httpx==0.28.1
idna==3.10
Jinja2==3.1.5
markdown-it-py==3.0.0
MarkupSafe==3.0.2
mdurl==0.1.2
motor==3.6.0
pydantic==2.9.2
pydantic_core==2.23.4
Pygments==2.18.0
pymongo==4.9.2
python-dotenv==1.0.1
python-multipart==0.0.20
pytz==2024.2
PyYAML==6.0.2
redis==5.2.0
requests==2.32.3
rich==13.9.4
rich-toolkit==0.12.0
shellingham==1.5.4
six==1.16.0
sniffio==1.3.1
starlette==0.41.2
typer==0.15.1
typing_extensions==4.12.2
tzlocal==5.2
urllib3==2.3.0
uvicorn==0.32.0
uvloop==0.21.0
watchfiles==1.0.3
websockets==14.1