Files
marquiz-metrics/app/main.py
13orlov 9e815b0619
Some checks failed
continuous-integration/drone/push Build is failing
feat(tests): Add test configuration and helpers
2025-08-23 22:17:53 +01:00

44 lines
1.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from fastapi import FastAPI
from loguru import logger
from contextlib import asynccontextmanager
from app.core.logging import setup_logging
from app.core.config import settings
from app.api.v1.endpoints import auth
from app.api.v1.endpoints import counters
# Вызываем настройку логирования в самом начале
setup_logging()
# --- НОВЫЙ, СОВРЕМЕННЫЙ СПОСОБ ОБРАБОТКИ СОБЫТИЙ ---
@asynccontextmanager
async def lifespan(app: FastAPI):
# Этот код выполняется один раз ПРИ СТАРТЕ приложения
logger.info("Application startup...")
logger.info(f"Log level is set to: {settings.LOG_LEVEL}")
logger.info("Service is ready to accept requests.")
yield # В этот момент приложение работает
# Этот код выполняется один раз ПРИ ОСТАНОВКЕ приложения
logger.info("Application shutdown...")
# Создаем главный объект приложения FastAPI и подключаем lifespan
app = FastAPI(
title="Marquiz Metrica Connector 2.0",
version="1.0.0",
description="Микросервис для автоматизации настройки api Яндекс.Метрики.",
lifespan=lifespan # <-- Подключаем наш новый обработчик
)
# Подключаем роутеры
app.include_router(auth.router, prefix="/api/v1/auth", tags=["Authentication"])
app.include_router(counters.router, prefix="/api/v1/counters", tags=["Counters"])
@app.get("/", tags=["Health Check"])
def health_check():
"""Эндпоинт для проверки работоспособности сервиса."""
logger.info("Health check endpoint was requested.")
return {"status": "ok", "message": "Welcome to Marquiz Metrica Connector!"}
logger.info("FastAPI app instance created and configured.")