aboutsummaryrefslogtreecommitdiff
path: root/scripts/rqtl2/entry.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-01-15 06:07:05 +0300
committerFrederick Muriuki Muriithi2024-01-15 06:07:05 +0300
commit8fe991c20f27702ee34ffcdd0cbc96e411db8c90 (patch)
tree509c0d1a00bf96bc3308802765e5ae63cfeb123c /scripts/rqtl2/entry.py
parentf89c08c392182b669d058a4c21feffde64b15ebb (diff)
downloadgn-uploader-8fe991c20f27702ee34ffcdd0cbc96e411db8c90.tar.gz
Extract common structure into separate modules.
Diffstat (limited to 'scripts/rqtl2/entry.py')
-rw-r--r--scripts/rqtl2/entry.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/scripts/rqtl2/entry.py b/scripts/rqtl2/entry.py
new file mode 100644
index 0000000..e2d70a6
--- /dev/null
+++ b/scripts/rqtl2/entry.py
@@ -0,0 +1,37 @@
+"""Build common script-entry structure."""
+from logging import Logger
+from typing import Callable
+from argparse import Namespace
+
+from redis import Redis
+from MySQLdb import Connection
+
+from qc_app.db_utils import database_connection
+from qc_app.check_connections import check_db, check_redis
+
+from scripts.redis_logger import setup_redis_logger
+
+def build_main(cli_args: Callable[[], Namespace],
+ run_fn: Callable[[Connection, Namespace], int],
+ logger: Logger,
+ loglevel: str = "INFO") -> Callable[[],int]:
+ """Build a function to be used as an entry-point for scripts."""
+ def main():
+ args = cli_args()
+ check_db(args.databaseuri)
+ check_redis(args.redisuri)
+ if not args.rqtl2bundle.exists():
+ logger.error("File not found: '%s'.", args.rqtl2bundle)
+ return 2
+
+ with (Redis.from_url(args.redisuri, decode_responses=True) as rconn,
+ database_connection(args.databaseuri) as dbconn):
+ logger.addHandler(setup_redis_logger(
+ rconn,
+ args.jobid,
+ f"{str(args.jobid)}:log-messages",
+ args.redisexpiry))
+ logger.setLevel(loglevel)
+ return run_fn(dbconn, args)
+
+ return main