From 7bf368edff3afdf911b976690f76918594066dde Mon Sep 17 00:00:00 2001 From: "Anna (Anya) Parker" <50943381+anna-parker@users.noreply.github.com> Date: Thu, 8 Aug 2024 13:27:35 +0200 Subject: [PATCH] Fix error handling --- .../flyway/sql/V1__Initial_Schema.sql | 4 +-- ena-submission/scripts/create_project.py | 27 +++++++++++-------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/ena-submission/flyway/sql/V1__Initial_Schema.sql b/ena-submission/flyway/sql/V1__Initial_Schema.sql index e1df4963a9..31b4f6fc19 100644 --- a/ena-submission/flyway/sql/V1__Initial_Schema.sql +++ b/ena-submission/flyway/sql/V1__Initial_Schema.sql @@ -34,7 +34,7 @@ CREATE TABLE sample_table ( status text not null, started_at timestamp not null, finished_at timestamp, - sample_metadata jsonb, + result jsonb, primary key (accession, version) ); @@ -46,6 +46,6 @@ CREATE TABLE assembly_table ( status text not null, started_at timestamp not null, finished_at timestamp, - assembly_metadata jsonb, + result jsonb, primary key (accession, version) ); \ No newline at end of file diff --git a/ena-submission/scripts/create_project.py b/ena-submission/scripts/create_project.py index db8b1861b6..b015774518 100644 --- a/ena-submission/scripts/create_project.py +++ b/ena-submission/scripts/create_project.py @@ -55,6 +55,9 @@ class Config: ena_submission_url: str ena_submission_password: str ena_submission_username: str + slack_hook: str + slack_token: str + slack_channel_id: str def construct_project_set_object( @@ -250,16 +253,17 @@ def project_table_create(db_config, config, retry_number=3): number_rows_updated = 0 tries = 0 while number_rows_updated != 1 and tries < retry_number: + if tries > 0: + # If state not correctly added retry + logger.warning( + f"Project created but DB update failed - reentry DB update #{tries}." + ) number_rows_updated = update_db_where_conditions( db_config, table_name="project_table", conditions=group_key, update_values=update_values, ) - # If state not correctly added retry - logger.warning( - f"Project created but DB update failed - reentry DB update #{tries}." - ) tries += 1 if number_rows_updated == 1: logger.info(f"Project creation for group_id {row["group_id"]} succeeded!") @@ -271,16 +275,17 @@ def project_table_create(db_config, config, retry_number=3): number_rows_updated = 0 tries = 0 while number_rows_updated != 1 and tries < retry_number: + if tries > 0: + # If state not correctly added retry + logger.warning( + f"Project creation failed and DB update failed - reentry DB update #{tries}." + ) number_rows_updated = update_db_where_conditions( db_config, table_name="project_table", conditions=group_key, update_values=update_values, ) - # If state not correctly added retry - logger.warning( - f"Project creation failed and DB update failed - reentry DB update #{tries}." - ) tries += 1 @@ -295,10 +300,10 @@ def project_table_handle_errors(db_config, config, time_threshold=15, slack_time entries_with_errors = find_errors_in_db( db_config, "project_table", time_threshold=time_threshold ) - if len(entries_with_errors) > 1: + if len(entries_with_errors) > 0: error_msg = ( - f"Found {len(entries_with_errors)} entries in project_table in status HAS_ERRORS", - f" for {time_threshold}m", + f"Found {len(entries_with_errors)} entries in project_table in status HAS_ERRORS" + f"of SUBMITTING for over {time_threshold}m" ) logger.warning(error_msg) send_slack_notification(