From 044184ef28a091519b7632d582387c26bf1543ea Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Mon, 18 Jul 2022 11:32:44 +0300 Subject: Check connections before launching * qc_app/__init__.py (refactor): Check connection before launching the application * qc_app/check_connections.py (new file): Add code to check connections * qc_app/db_utils.py (refactor): enable passing the database uri as an argument to the connection creation function. * scripts/worker.py (refactor): Use new code to check for redis connection. --- qc_app/__init__.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'qc_app/__init__.py') diff --git a/qc_app/__init__.py b/qc_app/__init__.py index 6b760b9..eefe236 100644 --- a/qc_app/__init__.py +++ b/qc_app/__init__.py @@ -7,6 +7,7 @@ from flask import Flask from .entry import entrybp from .parse import parsebp from .dbinsert import dbinsertbp +from .check_connections import check_db, check_redis def instance_path(): """Retrieve the `instance_path`. Raise an exception if not defined.""" @@ -25,6 +26,10 @@ def create_app(instance_dir): app.config.from_pyfile(os.path.join(os.getcwd(), "etc/default_config.py")) app.config.from_pyfile("config.py") # Override defaults with instance path + # Check the connection + check_db(app.config["SQL_URI"]) + check_redis(app.config["REDIS_URL"]) + # setup blueprints app.register_blueprint(entrybp, url_prefix="/") app.register_blueprint(parsebp, url_prefix="/parse") -- cgit v1.2.3