Files
notifications-api/app/status/healthcheck.py

47 lines
1.4 KiB
Python
Raw Normal View History

2025-04-14 13:36:14 -06:00
from flask import Blueprint, jsonify, make_response, request
2024-04-24 16:27:20 -04:00
from sqlalchemy import text
from app import db, version
2023-07-10 11:06:29 -07:00
from app.dao.organization_dao import dao_count_organizations_with_live_services
2021-03-10 13:55:06 +00:00
from app.dao.services_dao import dao_count_live_services
2023-08-29 14:54:30 -07:00
status = Blueprint("status", __name__)
2023-08-29 14:54:30 -07:00
@status.route("/", methods=["GET"])
@status.route("/_status", methods=["GET", "POST"])
2016-01-14 16:13:27 +00:00
def show_status():
2023-08-29 14:54:30 -07:00
if request.args.get("simple", None):
return jsonify(status="ok"), 200
else:
response = make_response(
2023-08-29 14:54:30 -07:00
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,
)
response.headers["Content-Type"] = "application/json"
return response
2023-08-29 14:54:30 -07:00
@status.route("/_status/live-service-and-organization-counts")
2023-07-10 11:06:29 -07:00
def live_service_and_organization_counts():
2025-04-14 13:36:14 -06:00
response = make_response(
jsonify(
2023-08-29 14:54:30 -07:00
organizations=dao_count_organizations_with_live_services(),
services=dao_count_live_services(),
),
2025-04-14 13:36:14 -06:00
200,
)
2025-04-14 13:32:10 -06:00
response.headers["Content-Type"] = "application/json"
return response
def get_db_version():
2023-08-29 14:54:30 -07:00
query = "SELECT version_num FROM alembic_version"
2024-04-24 16:27:20 -04:00
full_name = db.session.execute(text(query)).fetchone()[0]
return full_name