Skip to content

Commit

Permalink
Merge pull request #1381 from sul-dlss/t1379-fund-name-email
Browse files Browse the repository at this point in the history
Adds title and fund name to summary email
  • Loading branch information
jgreben authored Oct 29, 2024
2 parents 5af289b + 928f826 commit 5b4e2a3
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 10 deletions.
24 changes: 19 additions & 5 deletions libsys_airflow/plugins/digital_bookplates/dag_979_sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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()]
)
Expand Down
18 changes: 16 additions & 2 deletions libsys_airflow/plugins/digital_bookplates/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,22 @@ def _summary_add_979_email(dag_runs: list, folio_url: str) -> str:
<li>DAG Run <a href="{{ dag_url }}{{ dag_run_id|urlencode }}">{{ dag_run_id }}</a> {{ result.state }}<br>
Instances:
<ul>
{% for uuid in result.instance_uuids %}
<li><a href="{{ folio_url }}/inventory/view/{{ uuid }}">{{ uuid }}</a></li>
{% for instance in result.instances %}
<li><a href="{{ folio_url }}/inventory/view/{{ instance.uuid }}">{{ instance.uuid }}</a>
Funds:
<table>
<tr>
<th>Name (if available)</th>
<th>Title</th>
</tr>
{% for fund in instance.funds %}
<tr>
<td>{% if fund.name %}{{ fund.name }}{% endif %}</td>
<td>{{ fund.title }}</td>
</tr>
{% endfor %}
</table>
</li>
{% endfor %}
</ul>
</li>
Expand Down
27 changes: 24 additions & 3 deletions tests/digital_bookplates/test_bookplates_emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
],
},
],
}
}
Expand All @@ -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(
Expand Down

0 comments on commit 5b4e2a3

Please sign in to comment.