This is an automated email from the ASF dual-hosted git repository.
uranusjr pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new bab6dbec38 Move user-facing string to template (#26815)
bab6dbec38 is described below
commit bab6dbec3883084e5872123b515c2a8491c32380
Author: blag <[email protected]>
AuthorDate: Wed Oct 5 23:04:34 2022 -0700
Move user-facing string to template (#26815)
Co-authored-by: Jed Cunningham
<[email protected]>
---
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 ba14c7b519..7adfdc4589 100644
--- a/airflow/models/dag.py
+++ b/airflow/models/dag.py
@@ -200,13 +200,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"),
@@ -3416,7 +3419,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 452f508917..379fb05937 100644
--- a/tests/models/test_dag.py
+++ b/tests/models/test_dag.py
@@ -3032,12 +3032,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):