Skip to content

Commit

Permalink
feat(ingest): Add slack_hook to ingest, send notification when reinge…
Browse files Browse the repository at this point in the history
…st wants to change grouping and revoke old groups. (#2392)

* Add slack_hook to ingest, send notification when reingest wants to change grouping and revoke old groups.
  • Loading branch information
anna-parker authored Aug 13, 2024
1 parent 7c41100 commit f6bc4a4
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
1 change: 1 addition & 0 deletions ingest/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ for key, value in defaults.items():
if not key in config:
config[key] = value

config["slack_hook"] = os.getenv("SLACK_HOOK")
# Infer whether nucleotide sequences are segmented
config["segmented"] = len(config["nucleotide_sequences"]) > 1

Expand Down
25 changes: 25 additions & 0 deletions ingest/scripts/prepare_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@

import click
import orjsonl
import requests
import yaml


@dataclass
class Config:
segmented: str
nucleotide_sequences: list[str]
slack_hook: str
backend_url: str


logger = logging.getLogger(__name__)
Expand All @@ -37,6 +40,24 @@ def ids_to_add(fasta_id, config) -> set[str]:
return {fasta_id}


def notify(config: Config, text: str):
"""Send slack notification with revocation details"""
if config.slack_hook:
requests.post(config.slack_hook, data=json.dumps({"text": text}), timeout=10)
logger.warn(text)


def revocation_notification(config: Config, to_revoke: dict[str, dict[str, str]]):
"""Send slack notification with revocation details"""
text = (
f"{config.backend_url}: Ingest pipeline wants to add the following sequences"
f" which will lead to revocations: {to_revoke}. "
"If you agree with this run the regroup_and_revoke rule in the ingest pod:"
" `kubectl exec -it INGEST_POD_NAME -- snakemake regroup_and_revoke`."

This comment has been minimized.

Copy link
@anna-parker

anna-parker Aug 20, 2024

Author Contributor

kubectl exec -it INGEST_POD_NAME -- snakemake regroup_and_revoke does not actually work - first snakemake is located at /opt/conda/bin/snakemake. Second before running you need to stop the current snakemake rules, typically this would be by adding a .snakemake/.stopme file to the working directory but this doesn't work (you can add the file but snakemake doesn't stop). Also launching snakemake with exec doesn't work as snakemake can't find its dependencies, e.g. /usr/bin/bash: line 2: python: command not found Probably snakemake needs to be run in a specific way or there is another snakemake somewhere

)
notify(config, text)


@click.command()
@click.option("--config-file", required=True, type=click.Path(exists=True))
@click.option("--metadata-path", required=True, type=click.Path(exists=True))
Expand Down Expand Up @@ -102,10 +123,14 @@ def main(
metadata_revise.append(revise_record)
revise_ids.update(ids_to_add(fasta_id, config))

found_seq_to_revoke = False
for fasta_id in to_revoke:
metadata_submit_prior_to_revoke.append(metadata[fasta_id])
submit_prior_to_revoke_ids.update(ids_to_add(fasta_id, config))

if found_seq_to_revoke:
revocation_notification(config, to_revoke)

def write_to_tsv(data, filename):
if not data:
Path(filename).touch()
Expand Down
5 changes: 5 additions & 0 deletions kubernetes/loculus/templates/ingest-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ spec:
secretKeyRef:
name: ingest-ncbi
key: api-key
- name: SLACK_HOOK
valueFrom:
secretKeyRef:
name: slack-notifications
key: slack-hook
args:
- snakemake
- results/approved
Expand Down

0 comments on commit f6bc4a4

Please sign in to comment.