Skip to content

Commit

Permalink
Clean up logging for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
anna-parker committed Aug 14, 2024
1 parent 49be8bd commit 7453de9
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions ena-submission/scripts/create_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,24 @@ def get_sample_attributes(config, sample_metadata, row):


def construct_sample_set_object(
config, organism_metadata, sample_metadata, center_name, row, organism
config,
organism_metadata,
sample_metadata,
center_name,
row,
organism,
test=False,
):
if test:
alias = XmlAttribute(
f"{row["accession"]}:{organism}:{config.unique_project_suffix}:{datetime.now(tz=pytz.utc)}"
) # TODO(https://github.com/loculus-project/loculus/issues/2425): remove in production
else:
alias = XmlAttribute(f"{row["accession"]}:{organism}:{config.unique_project_suffix}")
list_sample_attributes = get_sample_attributes(config, sample_metadata, row)
sample_type = SampleType(
center_name=XmlAttribute(center_name),
alias=XmlAttribute(f"{row["accession"]}:{organism}:{config.unique_project_suffix}"),
# alias=XmlAttribute(
# f"{row["accession"]}:{organism}:{config.unique_project_suffix}:{datetime.now(tz=pytz.utc)}" # For testing
# ),
alias=alias,
title=f"{organism_metadata["scientific_name"]}: Genome sequencing",
description=(
f"Automated upload of {organism_metadata["scientific_name"]} sequences submitted by {center_name} from {config.db_name}",
Expand Down Expand Up @@ -148,6 +157,7 @@ def send_slack_notification(config: Config, comment: str, time: datetime, time_t
not _last_notification_sent
or time - timedelta(hours=time_threshold) > _last_notification_sent
):
logger.warning(comment)
comment = f"{config.backend_url}: " + comment
notify(slack_config, comment)
_last_notification_sent = time
Expand Down Expand Up @@ -275,7 +285,7 @@ def sample_table_create(db_config, config, retry_number=3):
organism_metadata = config.organisms[organism]["ingest"]

sample_set = construct_sample_set_object(
config, organism_metadata, sample_metadata, center_name, row, organism
config, organism_metadata, sample_metadata, center_name, row, organism, test=True
)
update_values = {"status": Status.SUBMITTING}
number_rows_updated = update_db_where_conditions(
Expand Down Expand Up @@ -353,7 +363,6 @@ def sample_table_handle_errors(db_config, config, time_threshold=15, slack_time_
f"ENA Submission pipeline found {len(entries_with_errors)} entries in sample_table in "
f"status HAS_ERRORS or SUBMITTING for over {time_threshold}m"
)
logger.warning(error_msg)
send_slack_notification(
config, error_msg, time=datetime.now(tz=pytz.utc), time_threshold=slack_time_threshold
)
Expand Down

0 comments on commit 7453de9

Please sign in to comment.