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. --- scripts/worker.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'scripts') diff --git a/scripts/worker.py b/scripts/worker.py index 4077ad1..fee4ec8 100644 --- a/scripts/worker.py +++ b/scripts/worker.py @@ -10,6 +10,7 @@ from tempfile import TemporaryFile from redis import Redis from qc_app import jobs +from qc_app.check_connections import check_redis def parse_args(): "Parse the command-line arguments" @@ -21,11 +22,7 @@ def parse_args(): parser.add_argument("job_id", help="The id of the job being processed") args = parser.parse_args() - try: - conn = Redis.from_url(args.redisurl) # pylint: disable=[unused-variable] - except ConnectionError as conn_err: # pylint: disable=[unused-variable] - print(traceback.format_exc(), file=sys.stderr) - sys.exit(1) + check_redis(args.redisurl) return args -- cgit v1.2.3