From aa9cafb5f17b5128e0505816973275c7fd06099c Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Thu, 5 Jun 2025 08:12:56 -0700 Subject: [PATCH 1/2] improve debug of external issues --- app/status/healthcheck.py | 49 ++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/app/status/healthcheck.py b/app/status/healthcheck.py index 16fd65a09..3c9093e8a 100644 --- a/app/status/healthcheck.py +++ b/app/status/healthcheck.py @@ -1,4 +1,4 @@ -from flask import Blueprint, jsonify, request +from flask import Blueprint, current_app, jsonify, request from sqlalchemy import text from app import db, version @@ -11,29 +11,40 @@ status = Blueprint("status", __name__) @status.route("/", methods=["GET"]) @status.route("/_status", methods=["GET", "POST"]) def show_status(): - if request.args.get("simple", None): - return jsonify(status="ok"), 200 - else: - return ( - jsonify( - status="ok", # This should be considered part of the public API - git_commit=version.__git_commit__, - build_time=version.__time__, - db_version=get_db_version(), - ), - 200, + try: + if request.args.get("simple", None): + return jsonify(status="ok"), 200 + else: + return ( + jsonify( + status="ok", # This should be considered part of the public API + git_commit=version.__git_commit__, + build_time=version.__time__, + db_version=get_db_version(), + ), + 200, + ) + except Exception as e: + current_app.logger.error( + f"Unexpected error in show_status: {str(e)}", exc_info=True ) @status.route("/_status/live-service-and-organization-counts") def live_service_and_organization_counts(): - return ( - jsonify( - organizations=dao_count_organizations_with_live_services(), - services=dao_count_live_services(), - ), - 200, - ) + try: + return ( + jsonify( + organizations=dao_count_organizations_with_live_services(), + services=dao_count_live_services(), + ), + 200, + ) + except Exception as e: + current_app.logger.error( + f"Unexpected error in live_service_and_organization_counts: {str(e)}", + exc_info=True, + ) def get_db_version(): From 2abcbc55602001d47831b41ec770b813e52906c2 Mon Sep 17 00:00:00 2001 From: Kenneth Kehl <@kkehl@flexion.us> Date: Thu, 5 Jun 2025 08:17:30 -0700 Subject: [PATCH 2/2] cleanup --- app/status/healthcheck.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/app/status/healthcheck.py b/app/status/healthcheck.py index 3c9093e8a..35e304f00 100644 --- a/app/status/healthcheck.py +++ b/app/status/healthcheck.py @@ -28,6 +28,7 @@ def show_status(): current_app.logger.error( f"Unexpected error in show_status: {str(e)}", exc_info=True ) + raise Exception(status_code=503, detail="Service temporarily unavailable") @status.route("/_status/live-service-and-organization-counts") @@ -45,9 +46,17 @@ def live_service_and_organization_counts(): f"Unexpected error in live_service_and_organization_counts: {str(e)}", exc_info=True, ) + raise Exception(status_code=503, detail="Service temporarily unavailable") def get_db_version(): - query = "SELECT version_num FROM alembic_version" - full_name = db.session.execute(text(query)).fetchone()[0] - return full_name + try: + query = "SELECT version_num FROM alembic_version" + full_name = db.session.execute(text(query)).fetchone()[0] + return full_name + except Exception as e: + current_app.logger.error( + f"Unexpected error in get_db_version: {str(e)}", + exc_info=True, + ) + raise Exception(status_code=503, detail="Database temporarily unavailable")