diff --git a/libsys_airflow/plugins/digital_bookplates/dag_979_sensor.py b/libsys_airflow/plugins/digital_bookplates/dag_979_sensor.py index 85d29c46..3ecae66f 100644 --- a/libsys_airflow/plugins/digital_bookplates/dag_979_sensor.py +++ b/libsys_airflow/plugins/digital_bookplates/dag_979_sensor.py @@ -11,7 +11,7 @@ class DAG979Sensor(BaseSensorOperator): def __init__(self, dag_runs: list, **kwargs): self.dag_runs: dict = {} for dag_run_id in dag_runs: - self.dag_runs[dag_run_id] = {'state': None, 'instance_uuid': []} + self.dag_runs[dag_run_id] = {'state': None, 'instances': []} super().__init__(**kwargs) def poke(self, context) -> bool: @@ -21,10 +21,24 @@ def poke(self, context) -> bool: if len(dag_runs) < 1: continue dag_run = dag_runs[0] - self.dag_runs[dag_run_id]['state'] = dag_run.get_state() - self.dag_runs[dag_run_id]['instance_uuids'] = list( - dag_run.conf['druids_for_instance_id'].keys() - ) + state = dag_run.get_state() + self.dag_runs[dag_run_id]['state'] = state + if state in ['success', 'failed']: + instances = [] + for instance, bookplates in dag_run.conf[ + 'druids_for_instance_id' + ].items(): + funds = [] + for bookplate in bookplates: + funds.append( + { + "name": bookplate.get("fund_name"), + "title": bookplate.get("title"), + } + ) + instances.append({"uuid": instance, "funds": funds}) + + self.dag_runs[dag_run_id]['instances'] = instances poke_result = all( [val['state'] in ['success', 'failed'] for val in self.dag_runs.values()] ) diff --git a/libsys_airflow/plugins/digital_bookplates/email.py b/libsys_airflow/plugins/digital_bookplates/email.py index 61174bae..d4007caf 100644 --- a/libsys_airflow/plugins/digital_bookplates/email.py +++ b/libsys_airflow/plugins/digital_bookplates/email.py @@ -108,8 +108,22 @@ def _summary_add_979_email(dag_runs: list, folio_url: str) -> str:
  • DAG Run {{ dag_run_id }} {{ result.state }}
    Instances:
  • diff --git a/tests/digital_bookplates/test_bookplates_emails.py b/tests/digital_bookplates/test_bookplates_emails.py index b7760854..68632577 100644 --- a/tests/digital_bookplates/test_bookplates_emails.py +++ b/tests/digital_bookplates/test_bookplates_emails.py @@ -313,9 +313,25 @@ def test_summary_add_979_dag_runs(mocker, mock_folio_variables): dag_runs = { "manual__2024-10-20T02:00:00+00:00": { "state": "success", - "instance_uuids": [ - "fddf7e4c-161e-4ae8-baad-058288f63e17", - "5394da8a-e503-424e-aca7-7ba73ddafc03", + "instances": [ + { + "uuid": "fddf7e4c-161e-4ae8-baad-058288f63e17", + "funds": [ + { + "name": "HOSKINS", + "title": "Janina Wojcicka Hoskins Book Fund for Polish Humanities", + } + ], + }, + { + "uuid": "5394da8a-e503-424e-aca7-7ba73ddafc03", + "funds": [ + { + "name": None, + "title": "David Jackman Jr. and Sally J. Jackman Endowed Book Fund for Archeology and Anthropology of Pre-Columbian Civilizations", + } + ], + }, ], } } @@ -334,6 +350,11 @@ def test_summary_add_979_dag_runs(mocker, mock_folio_variables): assert links[0].attrs['href'].startswith("https://sul-libsys-airflow.stanford.edu") assert links[1].attrs['href'].endswith("view/fddf7e4c-161e-4ae8-baad-058288f63e17") + tds = html_body.find_all("td") + assert tds[0].text == "HOSKINS" + assert len(tds[2].text) == 0 # Tests blank fund name + assert tds[3].text.startswith("David Jackman Jr. and Sally J. Jackman") + def test_summary_add_979_dag_runs_prod(mocker, mock_folio_variables): mock_send_email = mocker.patch(