diff options
author | Frederick Muriuki Muriithi | 2025-05-28 16:57:32 -0500 |
---|---|---|
committer | Frederick Muriuki Muriithi | 2025-05-28 16:57:32 -0500 |
commit | f86ab9915825bc9edd7ef7ac12f97edb94313113 (patch) | |
tree | 61541312031aa8006f81bcd3d2384531c94f39c4 | |
parent | 15c33a5c1f49cce6e229ed616598771ec79acc01 (diff) | |
download | gn-uploader-f86ab9915825bc9edd7ef7ac12f97edb94313113.tar.gz |
Maintain single list of tables — build logs and query from list
Maintain a list of tables to lock when running the script and build
the logging messages, and lock query from the list for easier
maintenance.
-rw-r--r-- | scripts/load_phenotypes_to_db.py | 26 |
1 files changed, 9 insertions, 17 deletions
diff --git a/scripts/load_phenotypes_to_db.py b/scripts/load_phenotypes_to_db.py index 766001a..8143d74 100644 --- a/scripts/load_phenotypes_to_db.py +++ b/scripts/load_phenotypes_to_db.py @@ -323,29 +323,21 @@ if __name__ == "__main__": # How do you check for a table lock? # https://oracle-base.com/articles/mysql/mysql-identify-locked-tables # `SHOW OPEN TABLES LIKE 'Publish%';` - logger.debug( - ("Locking database tables for the connection:" - "\n\t- %s\n\t- %s\n\t- %s\n\t- %s\n\t- %s\n"), + _db_tables_ = ( "Publication", + "Phenotype", "PublishXRef", "PublishData", "PublishSE", "NStrain") + + logger.debug( + ("Locking database tables for the connection:" + + "".join("\n\t- %s" for _ in _db_tables_) + "\n"), + *_db_tables_) cursor.execute(# Lock the tables to avoid race conditions - "LOCK TABLES " - "Publication WRITE, " - "PublishXRef WRITE, " - "PublishData WRITE, " - "PublishSE WRITE, " - "NStrain WRITE") - 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) + "LOCK TABLES " + ", ".join( + f"{_table} WRITE" for _table in _db_tables_)) logger.debug("Unlocking all database tables.") cursor.execute("UNLOCK TABLES") |