"""Logic for Hello. Verify that the application and its dependencies are available. """ from sentry_sdk import capture_exception from sqlalchemy.exc import SQLAlchemyError from artist import response from artist.connectors.mysql import db_session from artist.connectors.sentry import sentry_client from artist.constants import errors from artist.models.sql.heartbeat import QUERY_DB_HEARTBEAT def health_check(): """Health check handler. Checks database connection. 200 if OK, otherwise 503 service unavailable. Returns: Response: the system status. """ with db_session() as session: try: session.execute(QUERY_DB_HEARTBEAT) except SQLAlchemyError as e: print(e) capture_exception(e) return response.create_error_response( code=errors.INTERNAL_ERROR, message="could not connect to mysql", status=503, ) return response.Response(message={"status": "ok"}, status=200)