feat: реализация второй лабы по тз

This commit is contained in:
Enterxx2
2026-10-11 18:14:20 +03:00
parent a6c74c9bb0
commit ea2b432a22
100 changed files with 3416 additions and 428 deletions
+25 -5
View File
@@ -7,18 +7,38 @@ from fastapi import FastAPI
from application import api_endpoints, health_endpoints
from application.api.handlers import register_exception_handlers
from application.api.middlewares import RequestContextMiddleware
from config import APP_ENV, APP_HOST, APP_PORT, LOGGER, SHUTDOWN_TIMEOUT_SEC
from infrastructure import InMemoryStorage
from config import (
APP_ENV,
APP_HOST,
APP_PORT,
DB_STARTUP_TIMEOUT_SEC,
LOGGER,
PASSWORD_HASH_WORKERS,
SESSION_TTL_SECONDS,
SHUTDOWN_TIMEOUT_SEC,
)
from infrastructure import PasswordHasher, cache_manager, database_pool_manager
@asynccontextmanager
async def lifespan(app: FastAPI) -> AsyncIterator[None]:
app.state.storage = InMemoryStorage()
await database_pool_manager.create_pool(DB_STARTUP_TIMEOUT_SEC)
await database_pool_manager.apply_migrations()
cache_manager.create_client()
password_hasher = PasswordHasher(PASSWORD_HASH_WORKERS)
app.state.database = database_pool_manager
app.state.cache = cache_manager
app.state.password_hasher = password_hasher
app.state.is_ready = True
LOGGER.info(f"Application started, env={APP_ENV}, state is in-memory only")
LOGGER.info(
f"Application started, env={APP_ENV}, session ttl={SESSION_TTL_SECONDS} s"
)
yield
app.state.is_ready = False
LOGGER.info("Application stopped, in-memory state discarded")
await cache_manager.close()
await database_pool_manager.close()
password_hasher.close()
LOGGER.info("Application stopped, connections closed")
app = FastAPI(