Skip to content

Commit 07adc32

Browse files
Add lightweight DB healthcheck to root API for DEDICATED_SEALED_TX_MODE=1 (#771)
1 parent 7d1d679 commit 07adc32

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

app/main.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,14 @@
3030
from starlette import status
3131
from starlette.exceptions import HTTPException as StarletteHTTPException
3232

33+
from app.database import DBAsyncSession
3334
from app.exceptions import (
3435
AuthorizationError,
3536
BadRequestError,
3637
ContractRevertError,
3738
ServiceUnavailableError,
3839
)
39-
from app.log import output_access_log
40+
from app.log import LOG, output_access_log
4041
from app.routers.issuer import (
4142
account,
4243
bond,
@@ -137,7 +138,13 @@ async def api_call_handler(request: Request, call_next):
137138

138139

139140
@app.get("/", tags=["root"])
140-
async def root():
141+
async def root(db: DBAsyncSession):
142+
try:
143+
# Check DB Connection
144+
await db.connection()
145+
except Exception as err:
146+
LOG.exception("error")
147+
raise ServiceUnavailableError(err)
141148
libc.malloc_trim(0)
142149
return {"server": SERVER_NAME}
143150

0 commit comments

Comments
 (0)