mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-04 02:11:11 -05:00
Merge pull request #1755 from GSA/better_debug
improve debug of external issues
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
from flask import Blueprint, jsonify, request
|
from flask import Blueprint, current_app, jsonify, request
|
||||||
from sqlalchemy import text
|
from sqlalchemy import text
|
||||||
|
|
||||||
from app import db, version
|
from app import db, version
|
||||||
@@ -11,32 +11,52 @@ status = Blueprint("status", __name__)
|
|||||||
@status.route("/", methods=["GET"])
|
@status.route("/", methods=["GET"])
|
||||||
@status.route("/_status", methods=["GET", "POST"])
|
@status.route("/_status", methods=["GET", "POST"])
|
||||||
def show_status():
|
def show_status():
|
||||||
if request.args.get("simple", None):
|
try:
|
||||||
return jsonify(status="ok"), 200
|
if request.args.get("simple", None):
|
||||||
else:
|
return jsonify(status="ok"), 200
|
||||||
return (
|
else:
|
||||||
jsonify(
|
return (
|
||||||
status="ok", # This should be considered part of the public API
|
jsonify(
|
||||||
git_commit=version.__git_commit__,
|
status="ok", # This should be considered part of the public API
|
||||||
build_time=version.__time__,
|
git_commit=version.__git_commit__,
|
||||||
db_version=get_db_version(),
|
build_time=version.__time__,
|
||||||
),
|
db_version=get_db_version(),
|
||||||
200,
|
),
|
||||||
|
200,
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
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")
|
@status.route("/_status/live-service-and-organization-counts")
|
||||||
def live_service_and_organization_counts():
|
def live_service_and_organization_counts():
|
||||||
return (
|
try:
|
||||||
jsonify(
|
return (
|
||||||
organizations=dao_count_organizations_with_live_services(),
|
jsonify(
|
||||||
services=dao_count_live_services(),
|
organizations=dao_count_organizations_with_live_services(),
|
||||||
),
|
services=dao_count_live_services(),
|
||||||
200,
|
),
|
||||||
)
|
200,
|
||||||
|
)
|
||||||
|
except Exception as e:
|
||||||
|
current_app.logger.error(
|
||||||
|
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():
|
def get_db_version():
|
||||||
query = "SELECT version_num FROM alembic_version"
|
try:
|
||||||
full_name = db.session.execute(text(query)).fetchone()[0]
|
query = "SELECT version_num FROM alembic_version"
|
||||||
return full_name
|
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")
|
||||||
|
|||||||
Reference in New Issue
Block a user