Compare commits

..

No commits in common. "8dd30a2fa662db6421f430cf0192373e2da5bcb7" and "79e5151dd0cbac88fc40d31bcb563f2acb9e429f" have entirely different histories.

6 changed files with 18 additions and 9 deletions

View File

@ -9,6 +9,8 @@ services:
environment:
MONGO_HOST: "mongo.develop.sprinthub.ru"
MONGO_PASSWORD: $MONGO_PASSWORD_DEV
REDIS_HOST: "redis.develop.sprinthub.ru"
REDIS_PASSWORD: $REDIS_PASSWORD_DEV
deploy:
mode: replicated
restart_policy:

View File

@ -9,6 +9,8 @@ services:
environment:
MONGO_HOST: "mongo.sprinthub.ru"
MONGO_PASSWORD: $MONGO_PASSWORD_PROD
REDIS_HOST: "redis.sprinthub.ru"
REDIS_PASSWORD: $REDIS_PASSWORD_PROD
deploy:
mode: replicated
restart_policy:

View File

@ -40,4 +40,5 @@ jobs:
- name: deploy
env:
MONGO_PASSWORD_DEV: ${{ secrets.MONGO_PASSWORD_DEV }}
REDIS_PASSWORD_DEV: ${{ secrets.REDIS_PASSWORD_DEV }}
run: docker stack deploy --with-registry-auth -c ./.deploy/deploy-dev.yaml infra-development

View File

@ -40,4 +40,5 @@ jobs:
- name: deploy
env:
MONGO_PASSWORD_PROD: ${{ secrets.MONGO_PASSWORD_PROD }}
REDIS_PASSWORD_PROD: ${{ secrets.REDIS_PASSWORD_PROD }}
run: docker stack deploy --with-registry-auth -c ./.deploy/deploy-prod.yaml infra

View File

@ -9,22 +9,16 @@ from app.storage import redis
router = fastapi.APIRouter()
class Task(pydantic.BaseModel):
id: str
attempt: int
payload: dict
class Response(pydantic.BaseModel):
id: str
attempt: int
payload: dict
task: Task|None
@router.get('/api/v1/take', responses={404: {'description': 'Not found'}})
async def execute(queue: typing.Annotated[str, fastapi.Header()]) -> Response:
task = await tasks.take_task(queue)
async with redis.database.lock(queue):
task = await tasks.take_task(queue)
if not task:
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))
return Response(id=str(task._id), attempt=task.attempts, payload=task.payload)

View File

@ -0,0 +1,9 @@
import os
import redis.asyncio as connection
REDIS_HOST = os.getenv('REDIS_HOST', 'localhost')
REDIS_PASSWORD = os.getenv('REDIS_PASSWORD')
database = connection.Redis(host=REDIS_HOST, password=REDIS_PASSWORD)