Skip to content

Commit

Permalink
Try to test notifications work from preview instances.
Browse files Browse the repository at this point in the history
  • Loading branch information
anna-parker committed Aug 7, 2024
1 parent 6a8bba3 commit 024576b
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions ena-submission/scripts/get_ena_submission_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,24 @@ def get_data_for_submission(config, entries, db_config):
return data_dict


def send_slack_notification(config: Config, output_file: str):
slack_config = get_slack_config(
slack_hook_default=config.slack_hook,
slack_token_default=config.slack_token,
slack_channel_id_default=config.slack_channel_id,
)
if slack_config.slack_hook:
comment = (
f"{config.backend_url}: ENA Submission pipeline wants to submit the following sequences"
)
try:
response = upload_file_with_comment(slack_config, output_file, comment)
if not response.get("ok", False):
raise Exception
except Exception as e:
notify(slack_config, comment + f" - file upload to slack failed with Error {e}")


@click.command()
@click.option(
"--log-level",
Expand All @@ -85,12 +103,7 @@ def get_data_for_submission(config, entries, db_config):
required=False,
type=click.Path(),
)
@click.option(
"--slack-hook",
required=False,
type=click.Path(),
)
def get_ena_submission_list(log_level, config_file, output_file, slack_hook):
def get_ena_submission_list(log_level, config_file, output_file):
"""
Get a list of all sequences in state APPROVED_FOR_RELEASE without insdc-specific
metadata fields and not already in the ena_submission.submission_table.
Expand Down Expand Up @@ -122,22 +135,11 @@ def get_ena_submission_list(log_level, config_file, output_file, slack_hook):

if entries_to_submit:
Path(output_file).write_text(json.dumps(entries_to_submit))
if config.slack_hook:
slack_config = get_slack_config(
slack_hook_default=config.slack_hook,
slack_token_default=config.slack_token,
slack_channel_id_default=config.slack_channel_id,
)
comment = f"{config.backend_url}: ENA Submission pipeline wants to submit the following sequences"
try:
response = upload_file_with_comment(slack_config, output_file, comment)
if not response.get("ok", False):
raise Exception
except Exception as e:
notify(slack_config, comment + f" - file upload to slack failed with Error {e}")
send_slack_notification(config, output_file)
else:
logging.info("No sequences found to submit to ENA")
Path(output_file).write_text("")
send_slack_notification(config, output_file)


if __name__ == "__main__":
Expand Down

0 comments on commit 024576b

Please sign in to comment.