From 2fdabcaf36a287d8af11ab045f941ed39661a9fd Mon Sep 17 00:00:00 2001 From: Frederick Muriuki Muriithi Date: Fri, 12 Apr 2024 11:11:13 +0300 Subject: Move entry-point module to scripts package. This ensures the entry-point script/module is actually installed together with the rest of the code. --- scripts/qcapp_wsgi.py | 44 ++++++++++++++++++++++++++++++++++++++++++++ wsgi.py | 44 -------------------------------------------- 2 files changed, 44 insertions(+), 44 deletions(-) create mode 100644 scripts/qcapp_wsgi.py delete mode 100644 wsgi.py diff --git a/scripts/qcapp_wsgi.py b/scripts/qcapp_wsgi.py new file mode 100644 index 0000000..9fb63cb --- /dev/null +++ b/scripts/qcapp_wsgi.py @@ -0,0 +1,44 @@ +"""Run the application""" +import sys +from logging import getLogger, StreamHandler + +from flask import Flask + +from qc_app import create_app +from qc_app.check_connections import check_db, check_redis + +def check_and_build_app() -> Flask: + """Setup the application for running.""" + # Setup the app + appl = create_app() + + # Check connections + check_db(appl.config["SQL_URI"]) + check_redis(appl.config["REDIS_URL"]) + return appl + +def setup_logging(appl: Flask): + """Setup application logging""" + loglevel = appl.config["LOG_LEVEL"].upper() + + # Maybe call `logging.dictConfig(…)` here instead of all this stuff below + handler_stderr = StreamHandler(stream=sys.stderr) + appl.logger.addHandler(handler_stderr) + + rootlogger = getLogger() + rootlogger.addHandler(handler_stderr) + rootlogger.setLevel(loglevel) + + appl.logger.setLevel(loglevel) + +app = check_and_build_app() + +if __name__ != "__main__":# Running via gunicorn + gunicorn_logger = getLogger("gunicorn.error") + app.logger.handlers = gunicorn_logger.handlers + app.logger.setLevel(gunicorn_logger.level)#pylint: disable=[no-member] + +if __name__ == "__main__":# Running via flask + # Run the app + setup_logging(app) + app.run() diff --git a/wsgi.py b/wsgi.py deleted file mode 100644 index 9fb63cb..0000000 --- a/wsgi.py +++ /dev/null @@ -1,44 +0,0 @@ -"""Run the application""" -import sys -from logging import getLogger, StreamHandler - -from flask import Flask - -from qc_app import create_app -from qc_app.check_connections import check_db, check_redis - -def check_and_build_app() -> Flask: - """Setup the application for running.""" - # Setup the app - appl = create_app() - - # Check connections - check_db(appl.config["SQL_URI"]) - check_redis(appl.config["REDIS_URL"]) - return appl - -def setup_logging(appl: Flask): - """Setup application logging""" - loglevel = appl.config["LOG_LEVEL"].upper() - - # Maybe call `logging.dictConfig(…)` here instead of all this stuff below - handler_stderr = StreamHandler(stream=sys.stderr) - appl.logger.addHandler(handler_stderr) - - rootlogger = getLogger() - rootlogger.addHandler(handler_stderr) - rootlogger.setLevel(loglevel) - - appl.logger.setLevel(loglevel) - -app = check_and_build_app() - -if __name__ != "__main__":# Running via gunicorn - gunicorn_logger = getLogger("gunicorn.error") - app.logger.handlers = gunicorn_logger.handlers - app.logger.setLevel(gunicorn_logger.level)#pylint: disable=[no-member] - -if __name__ == "__main__":# Running via flask - # Run the app - setup_logging(app) - app.run() -- cgit v1.2.3