feat: функционал первой лабы перенос

This commit is contained in:
Enterxx2
2026-10-11 13:24:29 +03:00
parent 65003b6119
commit a6c74c9bb0
90 changed files with 2746 additions and 1 deletions
+51
View File
@@ -0,0 +1,51 @@
from collections.abc import AsyncIterator
from contextlib import asynccontextmanager
import uvicorn
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
@asynccontextmanager
async def lifespan(app: FastAPI) -> AsyncIterator[None]:
app.state.storage = InMemoryStorage()
app.state.is_ready = True
LOGGER.info(f"Application started, env={APP_ENV}, state is in-memory only")
yield
app.state.is_ready = False
LOGGER.info("Application stopped, in-memory state discarded")
app = FastAPI(
title="mtuci-labs-messanger",
description="мессенджер-конкурент-максу",
version="1.2.0",
lifespan=lifespan,
)
app.add_middleware(RequestContextMiddleware)
register_exception_handlers(app)
app.include_router(health_endpoints)
app.include_router(api_endpoints)
def main(host: str, port: int, shutdown_timeout: int) -> None:
"""Функция для запуска api"""
uvicorn.run(
app,
host=host,
port=port,
timeout_graceful_shutdown=shutdown_timeout,
access_log=False,
server_header=False,
)
if __name__ == "__main__":
main(host=APP_HOST, port=APP_PORT, shutdown_timeout=SHUTDOWN_TIMEOUT_SEC)