Skip to content

Commit

Permalink
Fix error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
anna-parker committed Aug 8, 2024
1 parent a9b7a8c commit 7bf368e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
4 changes: 2 additions & 2 deletions ena-submission/flyway/sql/V1__Initial_Schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);

Expand All @@ -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)
);
27 changes: 16 additions & 11 deletions ena-submission/scripts/create_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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!")
Expand All @@ -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


Expand All @@ -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(
Expand Down

0 comments on commit 7bf368e

Please sign in to comment.