mirror of
https://github.com/furyhawk/lta_datamall_api.git
synced 2026-07-21 10:16:52 +00:00
- Add CacheClient for managing Valkey interactions - Integrate caching into bus API routes for improved performance - Update .env.example and config.py for Valkey settings - Modify Makefile and README for Valkey service management - Add Valkey service to docker-compose - Include Valkey dependency in pyproject.toml and uv.lock
42 lines
957 B
Python
42 lines
957 B
Python
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI
|
|
|
|
from app.api.routes import bus, health
|
|
from app.core.config import get_settings
|
|
from app.services.cache import CacheClient
|
|
from app.services.lta_client import LTAClient
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
settings = get_settings()
|
|
lta_client = LTAClient(settings)
|
|
cache_client = CacheClient(settings)
|
|
await lta_client.startup()
|
|
await cache_client.startup()
|
|
app.state.lta_client = lta_client
|
|
app.state.cache_client = cache_client
|
|
yield
|
|
await lta_client.shutdown()
|
|
await cache_client.shutdown()
|
|
|
|
|
|
def create_app() -> FastAPI:
|
|
settings = get_settings()
|
|
|
|
app = FastAPI(
|
|
title=settings.app_name,
|
|
version=settings.app_version,
|
|
debug=settings.app_debug,
|
|
lifespan=lifespan,
|
|
)
|
|
|
|
app.include_router(health.router)
|
|
app.include_router(bus.router)
|
|
|
|
return app
|
|
|
|
|
|
app = create_app()
|