Skip to content

Commit

Permalink
add health endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
diversemix committed Jul 27, 2023
1 parent c93cd54 commit 46d096c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@
from app.logging_config import DEFAULT_LOGGING, setup_json_logging
from app.api.api_v1.routers import families_router
from fastapi import FastAPI
from fastapi_health import health
import uvicorn

from app.service.health import is_database_online


app = FastAPI(title="navigator-admin")
setup_json_logging(app)
add_pagination(app)
app.include_router(families_router, prefix="/api/v1", tags=["families"])

# add health endpoint
app.add_api_route("/health", health([is_database_online]))


@app.get("/api/v1", include_in_schema=False)
async def root():
Expand Down
11 changes: 11 additions & 0 deletions app/service/health.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from app.db.session import get_db


def is_database_online() -> bool:
"""
Checks database health.
TODO: More comprehensive health checks
"""

return get_db() is not None

0 comments on commit 46d096c

Please sign in to comment.