Skip to content

Commit

Permalink
Added database state to healthz endoint for eoAPI stac component. (#118)
Browse files Browse the repository at this point in the history
  • Loading branch information
pantierra authored Dec 13, 2024
1 parent 19e84c9 commit 547ee83
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion runtimes/eoapi/stac/eoapi/stac/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,13 @@ async def viewer_page(request: Request):

@app.get("/healthz", response_class=JSONResponse)
async def healthz_page(request: Request):
return JSONResponse({'ping': 'pong!'})
response = { "database_online": "false" }

try:
async with request.app.state.get_connection(request, "r") as conn:
await conn.fetchval("SELECT 1")
response["database_online"] = 'true'
except Exception as e:
response["database_error"] = str(e)

return JSONResponse(response)

0 comments on commit 547ee83

Please sign in to comment.