about summary refs log tree commit diff
path: root/scripts
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2025-05-05 15:46:48 -0500
committerFrederick Muriuki Muriithi2025-05-05 16:20:11 -0500
commitfc5bc996e18dd67cccb6784624b038800f986021 (patch)
tree0b51c78d6fddba81cf664c22ede221e063ae0c5c /scripts
parenta4e6fddea8a25b30b775482ee9717386389486ad (diff)
downloadgn-uploader-fc5bc996e18dd67cccb6784624b038800f986021.tar.gz
Init setup and script for async job to load phenotypes into database
Diffstat (limited to 'scripts')
-rw-r--r--scripts/load_phenotypes_to_db.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/scripts/load_phenotypes_to_db.py b/scripts/load_phenotypes_to_db.py
new file mode 100644
index 0000000..fa710a6
--- /dev/null
+++ b/scripts/load_phenotypes_to_db.py
@@ -0,0 +1,61 @@
+import uuid
+import logging
+import argparse
+from pathlib import Path
+
+from gn_libs import jobs, mysqldb, sqlite3
+
+logging.basicConfig(
+    format="%(asctime)s — %(filename)s:%(lineno)s — %(levelname)s: %(message)s")
+logger = logging.getLogger(__name__)
+
+
+def load_data(conn, job):
+    """Load the data attached in the given job."""
+    pass
+
+
+if __name__ == "__main__":
+    def parse_args():
+        """Setup command-line arguments."""
+        parser = argparse.ArgumentParser(
+            prog="load_phenotypes_to_db",
+            description="Process the phenotypes' data and load it into the database.")
+        parser.add_argument("db_uri", type=str, help="MariaDB/MySQL connection URL")
+        parser.add_argument(
+            "jobs_db_path", type=Path, help="Path to jobs' SQLite database.")
+        parser.add_argument("job_id", type=uuid.UUID, help="ID of the running job")
+        parser.add_argument(
+            "--log-level",
+            type=str,
+            help="Determines what is logged out.",
+            choices=("debug", "info", "warning", "error", "critical"),
+            default="info")
+        return parser.parse_args()
+
+    def setup_logging(log_level: str):
+        """Setup logging for the script."""
+        logger.setLevel(log_level)
+        logging.getLogger("uploader.phenotypes.models").setLevel(log_level)
+
+
+    def main():
+        """Entry-point for this script."""
+        args = parse_args()
+        setup_logging(args.log_level.upper())
+
+        with (mysqldb.database_connection(args.db_uri) as conn,
+              sqlite3.connection(args.jobs_db_path) as jobs_conn):
+            try:
+                return load_data(conn, jobs.job(jobs_conn, args.job_id))
+            except jobs.jobs.JobNotFound as _jne:
+                logger.error("Could not find job with ID: %s", args.job_id)
+            except Exception as _exc:
+                logger.error("Loading failed with general exception!",
+                             exc_info=True,
+                             stack_info=True)
+
+        return 1
+
+
+    main()