feat(lab3): add nginx load balancing, scaling, idempotency and failover script

This commit is contained in:
2026-10-23 03:54:09 +03:00
parent 0ab3a341aa
commit a99e4c72c6
21 changed files with 973 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
import os
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession, async_sessionmaker
from pydantic_settings import BaseSettings
class Settings(BaseSettings):
DATABASE_URL: str = os.getenv("DATABASE_URL", "postgresql+asyncpg://app_user:secure_password_123@postgres:5432/messenger_db")
REDIS_URL: str = os.getenv("REDIS_URL", "redis://redis:6379/0")
SESSION_TTL_SECONDS: int = int(os.getenv("SESSION_TTL_SECONDS", "3600"))
settings = Settings()
engine = create_async_engine(
settings.DATABASE_URL,
pool_size=10,
max_overflow=20,
pool_timeout=30,
pool_recycle=1800
)
async_session_maker = async_sessionmaker(engine, class_=AsyncSession, expire_on_commit=False)
async def get_db():
async with async_session_maker() as session:
try:
yield session
await session.commit()
except Exception:
await session.rollback()
raise
finally:
await session.close()