bettersight-statement-extra.../backend/routes/health.py

32 lines
1023 B
Python

# Health check endpoint - new in this restructure (ENTERPRISE_STANDARDS.md
# lists this as a non-negotiable item even outside the monitoring/alerting
# infrastructure around it, which is explicitly out of scope here - see
# CLAUDE.md's Architecture section).
import requests
from flask import Blueprint, jsonify
import dependencies
health_bp = Blueprint("health", __name__)
@health_bp.route("/health")
def health():
"""
Reports whether this service and its one real dependency (the
self-hosted Docling container) are reachable.
Data flow:
(no input)
-> GET DOCLING_URL/health
-> JSON response: {"status": "ok"|"degraded", "docling": "ok"|"unreachable"}
"""
try:
resp = requests.get(f"{dependencies.DOCLING_URL}/health", timeout=5)
docling_ok = resp.status_code == 200
except Exception:
docling_ok = False
status = "ok" if docling_ok else "degraded"
return jsonify({"status": status, "docling": "ok" if docling_ok else "unreachable"}), 200