34 lines
861 B
Python
34 lines
861 B
Python
|
|
"""FastAPI application entry point."""
|
||
|
|
|
||
|
|
from contextlib import asynccontextmanager
|
||
|
|
from typing import AsyncGenerator
|
||
|
|
|
||
|
|
from fastapi import FastAPI
|
||
|
|
|
||
|
|
from app.api.v1 import health
|
||
|
|
from app.config import settings
|
||
|
|
from app.db import db, redis_client
|
||
|
|
|
||
|
|
|
||
|
|
@asynccontextmanager
|
||
|
|
async def lifespan(app: FastAPI) -> AsyncGenerator[None, None]:
|
||
|
|
"""Manage application lifecycle - connect/disconnect resources."""
|
||
|
|
# Startup
|
||
|
|
await db.connect(settings.database_url)
|
||
|
|
await redis_client.connect(settings.redis_url)
|
||
|
|
yield
|
||
|
|
# Shutdown
|
||
|
|
await redis_client.disconnect()
|
||
|
|
await db.disconnect()
|
||
|
|
|
||
|
|
|
||
|
|
app = FastAPI(
|
||
|
|
title="IncidentOps",
|
||
|
|
description="Incident management API with multi-tenant org support",
|
||
|
|
version="0.1.0",
|
||
|
|
lifespan=lifespan,
|
||
|
|
)
|
||
|
|
|
||
|
|
# Include routers
|
||
|
|
app.include_router(health.router, prefix=settings.api_v1_prefix, tags=["health"])
|