Skip to content

Commit 43c6267

Browse files
committed
Add health endpoint
1 parent 4caf1f5 commit 43c6267

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

app_factory.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
from flask_jwt_extended import JWTManager
44
from src.utils.constants import SERVICE_ACCOUNT_PATH, JWT_SECRET_KEY
55
from datetime import datetime
6-
from flask import Flask, render_template
6+
from flask import Flask, jsonify, render_template
7+
from sqlalchemy import text
78
from graphene import Schema
89
from graphql.utils import schema_printer
910
from src.database import db_session, init_db
@@ -89,6 +90,14 @@ def check_if_token_revoked(jwt_header, jwt_payload: dict) -> bool:
8990
def index():
9091
return render_template("index.html")
9192

93+
@app.route("/health")
94+
def health_check():
95+
try:
96+
db_session.execute(text("SELECT 1"))
97+
return jsonify({"status": "healthy", "database": "connected"}), 200
98+
except Exception:
99+
return jsonify({"status": "unhealthy", "database": "disconnected"}), 503
100+
92101
app.add_url_rule("/graphql", view_func=GraphQLView.as_view("graphql", schema=schema, graphiql=True))
93102

94103
@app.teardown_appcontext

0 commit comments

Comments
 (0)