ashb commented on code in PR #48747:
URL: https://github.com/apache/airflow/pull/48747#discussion_r2027448063


##########
providers/standard/src/airflow/providers/standard/operators/trigger_dagrun.py:
##########
@@ -304,8 +303,42 @@ def _trigger_dag_af_2(self, context, run_id, 
parsed_logical_date):
                     self.log.info("%s finished with allowed state %s", 
self.trigger_dag_id, state)
                     return
 
+    def execute_complete(self, context: Context, event: tuple[str, dict[str, 
Any]]):
+        if AIRFLOW_V_3_0_PLUS:

Review Comment:
   Lets not have one impl here, and another one in 
`_trigger_dag_run_af_2_execute_complete`
   
   This fn should just "dispatch" to the af2 or af3 function



##########
airflow-core/tests/unit/jobs/test_triggerer_job.py:
##########
@@ -734,3 +734,80 @@ async def 
test_trigger_can_access_variables_connections_and_xcoms(session, dag_m
             "xcom": '"some_xcom_value"',
         }
     }
+
+
+class CustomTriggerDagRun(BaseTrigger):
+    def __init__(self, trigger_dag_id, run_ids, states, logical_dates):
+        self.trigger_dag_id = trigger_dag_id
+        self.run_ids = run_ids
+        self.states = states
+        self.logical_dates = logical_dates
+
+    def serialize(self) -> tuple[str, dict[str, Any]]:
+        return (
+            f"{type(self).__module__}.{type(self).__qualname__}",
+            {
+                "trigger_dag_id": self.trigger_dag_id,
+                "run_ids": self.run_ids,
+                "states": self.states,
+                "logical_dates": self.logical_dates,
+            },
+        )
+
+    async def run(self, **args) -> AsyncIterator[TriggerEvent]:
+        from airflow.sdk.execution_time.context import get_dr_count
+
+        dag_run_states_count = await sync_to_async(get_dr_count)(
+            dag_id=self.trigger_dag_id,
+            run_ids=self.run_ids,
+            states=self.states,
+            logical_dates=self.logical_dates,
+        )
+        yield TriggerEvent({"count": dag_run_states_count})
+
+
[email protected](
+    reason="We know that test is flaky and have no time to fix it before 3.0. "
+    "We should fix it later. TODO: AIP-72"
+)
[email protected]
[email protected](reruns=2, reruns_delay=10)
[email protected]_timeout(30)

Review Comment:
   Likely yes, as it's using the same `DummyTriggerRunnerSupervisor` that is 
the cause of the flake



##########
providers/standard/src/airflow/providers/standard/operators/trigger_dagrun.py:
##########
@@ -304,8 +303,42 @@ def _trigger_dag_af_2(self, context, run_id, 
parsed_logical_date):
                     self.log.info("%s finished with allowed state %s", 
self.trigger_dag_id, state)
                     return
 
+    def execute_complete(self, context: Context, event: tuple[str, dict[str, 
Any]]):
+        if AIRFLOW_V_3_0_PLUS:
+            ti = context["ti"]
+            run_ids = event[1]["run_ids"]
+
+            failed_run_id_conditions = []
+
+            for run_id in run_ids:
+                state = ti.get_dagrun_state(
+                    dag_id=self.trigger_dag_id,
+                    run_id=run_id,
+                )

Review Comment:
   Since we are already accessing the DB in the trigger, why don't we have it 
collect the dag run state and send it along in the event? Seems better to only 
need to add one new message type, rather than two.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to