Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
math_tutor_dev
public_math_tutor
Commits
f1184f7f
Commit
f1184f7f
authored
Jun 17, 2026
by
Kantz
Browse files
health-check gefixed
parent
217c2686
Changes
2
Hide whitespace changes
Inline
Side-by-side
math-tutor/backend/app/api/health.py
View file @
f1184f7f
from
__future__
import
annotations
import
asyncio
import
logging
from
threading
import
Lock
from
typing
import
Any
,
Dict
...
...
@@ -177,17 +176,15 @@ async def _probe_mcp_server() -> dict:
return
{
"status"
:
"error"
,
"url"
:
url
,
"detail"
:
str
(
exc
)}
def
_check_mcp
()
->
dict
:
async
def
_check_mcp
()
->
dict
:
if
not
config
.
get_llm_tool_use_enabled
():
return
{
"status"
:
"disabled"
}
return
a
syncio
.
run
(
_probe_mcp_server
()
)
return
a
wait
_probe_mcp_server
()
@
router
.
get
(
"/api/health"
)
def
health
()
->
Dict
[
str
,
Any
]:
async
def
_health_payload
()
->
Dict
[
str
,
Any
]:
services
=
{
**
_check_selected_llm_provider
(),
"mcp"
:
_check_mcp
(),
"mcp"
:
await
_check_mcp
(),
"postgres"
:
_check_postgres
(),
"llm_quota"
:
_check_llm_quota
(),
}
...
...
@@ -198,6 +195,11 @@ def health() -> Dict[str, Any]:
return
{
"status"
:
overall
,
"services"
:
services
}
@
router
.
get
(
"/api/health"
)
async
def
health
()
->
Dict
[
str
,
Any
]:
return
await
_health_payload
()
@
router
.
get
(
"/api/health/ready"
,
response_model
=
None
)
def
readiness
()
->
Any
:
state
=
get_readiness_state
()
...
...
@@ -206,8 +208,8 @@ def readiness() -> Any:
return
JSONResponse
(
status_code
=
503
,
content
=
state
)
def
run_startup_checks
()
->
Dict
[
str
,
Any
]:
result
=
health
()
async
def
run_startup_checks
()
->
Dict
[
str
,
Any
]:
result
=
await
_health_payload
()
status
=
result
.
get
(
"status"
)
if
status
==
"ok"
:
logger
.
info
(
"Startup health check OK"
)
...
...
math-tutor/backend/app/main.py
View file @
f1184f7f
...
...
@@ -15,7 +15,7 @@ logger = logging.getLogger(__name__)
@
asynccontextmanager
async
def
lifespan
(
_app
:
FastAPI
):
health
.
set_readiness_starting
()
startup_result
=
health
.
run_startup_checks
()
startup_result
=
await
health
.
run_startup_checks
()
if
startup_result
.
get
(
"status"
)
!=
"ok"
:
health
.
set_readiness_failed
(
"Startup health checks degraded"
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment