Files
gogo-telefon/gogo/main.py

56 lines
1.4 KiB
Python
Raw Normal View History

"""FastAPI application assembly."""
from __future__ import annotations
import logging
from contextlib import asynccontextmanager
from fastapi import FastAPI
from gogo.api import actions, health, webhooks
from gogo.config import get_settings
logging.basicConfig(
level=logging.INFO, format="%(asctime)s %(levelname)s %(name)s %(message)s"
)
@asynccontextmanager
async def lifespan(app: FastAPI):
scheduler = None
if get_settings().env != "test":
from gogo.jobs import build_scheduler
scheduler = build_scheduler()
scheduler.start()
yield
if scheduler:
scheduler.shutdown(wait=False)
def create_app() -> FastAPI:
from gogo.admin.router import router as admin_router
from gogo.api.internal import router as internal_router
from gogo.chat.router import router as chat_router
from gogo.dashboard.router import router as dashboard_router
app = FastAPI(title="Gogo Telefon", docs_url=None, redoc_url=None, lifespan=lifespan)
app.include_router(health.router)
app.include_router(actions.router)
app.include_router(webhooks.router)
app.include_router(chat_router)
app.include_router(dashboard_router)
app.include_router(admin_router)
app.include_router(internal_router)
@app.get("/", include_in_schema=False)
async def root():
from fastapi.responses import RedirectResponse
return RedirectResponse("/dash")
return app
app = create_app()