Some checks failed
Run linters on applied template / Python 3.13 lint and build (push) Failing after 39s
This is a FastAPI backend microservice template used with `copier` utility. Features of applied template are: - Configuration file processing logic - Metrics and tracing (both optional) configuration available - Debug endpoints - Database migration commands, prepared Alembic environment - Database usage example in ping_db endpoint - gitea sanity check pipeline
44 lines
1.3 KiB
Django/Jinja
44 lines
1.3 KiB
Django/Jinja
"""System endpoints are defined here."""
|
|
|
|
import fastapi
|
|
from starlette import status
|
|
|
|
from {{project_slug}}.dependencies import connection_manager_dep
|
|
from {{project_slug}}.logic import system as system_logic
|
|
from {{project_slug}}.schemas import PingResponse
|
|
|
|
from .routers import system_router
|
|
|
|
|
|
@system_router.get("/", status_code=status.HTTP_307_TEMPORARY_REDIRECT, include_in_schema=False)
|
|
@system_router.get("/api/", status_code=status.HTTP_307_TEMPORARY_REDIRECT, include_in_schema=False)
|
|
async def redirect_to_swagger_docs():
|
|
"""Redirects to **/api/docs** from **/**"""
|
|
return fastapi.responses.RedirectResponse("/api/docs", status_code=status.HTTP_307_TEMPORARY_REDIRECT)
|
|
|
|
|
|
@system_router.get(
|
|
"/health_check/ping",
|
|
response_model=PingResponse,
|
|
status_code=status.HTTP_200_OK,
|
|
)
|
|
async def ping():
|
|
"""
|
|
Check that application is alive.
|
|
"""
|
|
return PingResponse()
|
|
|
|
|
|
@system_router.get(
|
|
"/health_check/ping_db",
|
|
response_model=PingResponse,
|
|
status_code=status.HTTP_200_OK,
|
|
)
|
|
async def ping_db(request: fastapi.Request, readonly: bool = False):
|
|
"""
|
|
Check that database connection is valid.
|
|
"""
|
|
connection_manager = connection_manager_dep.obtain(request)
|
|
|
|
return await system_logic.ping_db(connection_manager, readonly)
|