[add]: DB_URI #60
+27
-23
@@ -20,40 +20,44 @@ from flask_jwt_extended import (
|
||||
def create_app():
|
||||
"""Factory function to create a Flask app instance"""
|
||||
# import oracledb
|
||||
|
||||
|
||||
# oracledb.init_oracle_client(lib_dir=None)
|
||||
|
||||
app = Flask(__name__)
|
||||
try:
|
||||
|
||||
# Load configuration
|
||||
app.config.from_object(Config)
|
||||
app = Flask(__name__)
|
||||
|
||||
CORS(app)
|
||||
# Load configuration
|
||||
app.config.from_object(Config)
|
||||
|
||||
JWTManager(app)
|
||||
CORS(app, supports_credentials=True)
|
||||
CORS(app)
|
||||
|
||||
# Swagger Doc
|
||||
SWAGGER_URL = app.config.get("SWAGGER_URL")
|
||||
API_URL = app.config.get("API_URL")
|
||||
JWTManager(app)
|
||||
CORS(app, supports_credentials=True)
|
||||
|
||||
# Register blueprints
|
||||
app.register_blueprint(api)
|
||||
# Swagger Doc
|
||||
SWAGGER_URL = app.config.get("SWAGGER_URL")
|
||||
API_URL = app.config.get("API_URL")
|
||||
|
||||
swagger_ui_blueprint = get_swaggerui_blueprint(SWAGGER_URL, API_URL)
|
||||
app.register_blueprint(swagger_ui_blueprint, url_prefix=SWAGGER_URL)
|
||||
# Register blueprints
|
||||
app.register_blueprint(api)
|
||||
|
||||
# Error Handlers
|
||||
register_error_handlers(app)
|
||||
swagger_ui_blueprint = get_swaggerui_blueprint(SWAGGER_URL, API_URL)
|
||||
app.register_blueprint(swagger_ui_blueprint, url_prefix=SWAGGER_URL)
|
||||
|
||||
from . import models
|
||||
# Error Handlers
|
||||
register_error_handlers(app)
|
||||
|
||||
# Initialize Flask-Mail
|
||||
mail.init_app(app)
|
||||
from . import models
|
||||
|
||||
# Database and Migrations
|
||||
db.init_app(app)
|
||||
# Initialize Flask-Mail
|
||||
mail.init_app(app)
|
||||
|
||||
migrate.init_app(app, db)
|
||||
# Database and Migrations
|
||||
db.init_app(app)
|
||||
|
||||
return app
|
||||
migrate.init_app(app, db)
|
||||
|
||||
return app
|
||||
except Exception as e:
|
||||
print(f"An unexpected error occurred: {e}")
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
from sqlite3 import DatabaseError
|
||||
from app.api.integrations.events_service import EventServiceIntegration
|
||||
from flask import Blueprint, request, jsonify, send_from_directory
|
||||
from app.api.services import (
|
||||
@@ -24,6 +23,7 @@ from flask_jwt_extended import (
|
||||
from sqlalchemy import text
|
||||
from app.extensions import db
|
||||
from app.config import settings
|
||||
from urllib.parse import urlparse
|
||||
|
||||
|
||||
api = Blueprint("api", __name__)
|
||||
@@ -42,10 +42,10 @@ def swagger_json():
|
||||
return send_from_directory(swagger_dir, "digifi_swagger.json")
|
||||
|
||||
|
||||
@api.route("/swagger/<path:filename>")
|
||||
def serve_paths(filename):
|
||||
swagger_dir = os.path.join("swagger")
|
||||
return send_from_directory(swagger_dir, filename)
|
||||
# @api.route("/swagger/<path:filename>")
|
||||
# def serve_paths(filename):
|
||||
# swagger_dir = os.path.join("swagger")
|
||||
# return send_from_directory(swagger_dir, filename)
|
||||
|
||||
|
||||
# EligibilityCheck Endpoint
|
||||
@@ -122,15 +122,24 @@ def notification_callback():
|
||||
# Health Check Endpoint
|
||||
@api.route("/health", methods=["GET"])
|
||||
def health_check():
|
||||
|
||||
SQLALCHEMY_DATABASE_URI = settings.SQLALCHEMY_DATABASE_URI
|
||||
response = {}
|
||||
db_status = "Connection Successful"
|
||||
events_service_status = "Connection Successful"
|
||||
errors = []
|
||||
status = "ok"
|
||||
|
||||
# Extract the database URI
|
||||
try:
|
||||
db_uri = db.engine.url.render_as_string(hide_password=False)
|
||||
db_uri = db_uri
|
||||
except Exception as e:
|
||||
db_uri = "Unavailable"
|
||||
|
||||
|
||||
# Check database connection
|
||||
try:
|
||||
logger.info(f"Database Health == : {SQLALCHEMY_DATABASE_URI}")
|
||||
db.session.execute(text("SELECT 1"))
|
||||
except Exception as e:
|
||||
db_status = "Connection Failed"
|
||||
@@ -157,6 +166,7 @@ def health_check():
|
||||
response = {
|
||||
"status": status,
|
||||
"db_status": db_status,
|
||||
"db_uri": db_uri,
|
||||
"events_service_status": events_service_status,
|
||||
"errors": errors or None
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user