You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by ep...@apache.org on 2022/10/18 13:10:40 UTC
[airflow] 24/41: Move user-facing string to template (#26815)
This is an automated email from the ASF dual-hosted git repository.
ephraimanierobi pushed a commit to branch v2-4-test
in repository https://gitbox.apache.org/repos/asf/airflow.git
commit 9bcf5b342e44ff5b749f9ff4318d61546df4428e
Author: blag <bl...@users.noreply.github.com>
AuthorDate: Wed Oct 5 23:04:34 2022 -0700
Move user-facing string to template (#26815)
Co-authored-by: Jed Cunningham <66...@users.noreply.github.com>
(cherry picked from commit bab6dbec3883084e5872123b515c2a8491c32380)
---
airflow/models/dag.py | 9 ++++++---
airflow/www/templates/airflow/dags.html | 4 +++-
tests/models/test_dag.py | 15 ++++++++++++---
3 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/airflow/models/dag.py b/airflow/models/dag.py
index 1a6b9906b5..6b5bdde6de 100644
--- a/airflow/models/dag.py
+++ b/airflow/models/dag.py
@@ -198,13 +198,16 @@ def get_last_dagrun(dag_id, session, include_externally_triggered=False):
return query.first()
-def get_dataset_triggered_next_run_info(dag_ids: list[str], *, session: Session) -> dict[str, str]:
+def get_dataset_triggered_next_run_info(dag_ids: list[str], *, session: Session) -> dict[str, dict[str, int]]:
"""
Given a list of dag_ids, get string representing how close any that are dataset triggered are
their next run, e.g. "1 of 2 datasets updated"
"""
return {
- x.dag_id: f"{x.ready} of {x.total} datasets updated"
+ x.dag_id: {
+ "ready": x.ready,
+ "total": x.total,
+ }
for x in session.query(
DagScheduleDatasetReference.dag_id,
func.count().label("total"),
@@ -3338,7 +3341,7 @@ class DagModel(Base):
)
@provide_session
- def get_dataset_triggered_next_run_info(self, *, session=NEW_SESSION) -> str | None:
+ def get_dataset_triggered_next_run_info(self, *, session=NEW_SESSION) -> dict[str, int] | None:
if self.schedule_interval != "Dataset":
return None
return get_dataset_triggered_next_run_info([self.dag_id], session=session)[self.dag_id]
diff --git a/airflow/www/templates/airflow/dags.html b/airflow/www/templates/airflow/dags.html
index 0884a06c17..c675b4a05a 100644
--- a/airflow/www/templates/airflow/dags.html
+++ b/airflow/www/templates/airflow/dags.html
@@ -308,7 +308,9 @@
data-dag-id="{{ dag.dag_id }}"
data-summary="{{ dataset_triggered_next_run_info[dag.dag_id] }}"
>
- {{ dataset_triggered_next_run_info[dag.dag_id] }}
+ {% with ds_info = dataset_triggered_next_run_info[dag.dag_id] %}
+ {{ ds_info.ready }} of {{ ds_info.total }} datasets updated
+ {% endwith %}
</div>
</span>
{% endif %}
diff --git a/tests/models/test_dag.py b/tests/models/test_dag.py
index 54634e463f..775f557094 100644
--- a/tests/models/test_dag.py
+++ b/tests/models/test_dag.py
@@ -2953,12 +2953,21 @@ def test_get_dataset_triggered_next_run_info(dag_maker):
session.flush()
info = get_dataset_triggered_next_run_info([dag1.dag_id], session=session)
- assert "0 of 1 datasets updated" == info[dag1.dag_id]
+ assert info[dag1.dag_id] == {
+ "ready": 0,
+ "total": 1,
+ }
# This time, check both dag2 and dag3 at the same time (tests filtering)
info = get_dataset_triggered_next_run_info([dag2.dag_id, dag3.dag_id], session=session)
- assert "1 of 2 datasets updated" == info[dag2.dag_id]
- assert "1 of 3 datasets updated" == info[dag3.dag_id]
+ assert info[dag2.dag_id] == {
+ "ready": 1,
+ "total": 2,
+ }
+ assert info[dag3.dag_id] == {
+ "ready": 1,
+ "total": 3,
+ }
def test_dag_uses_timetable_for_run_id(session):