yuqian90 commented on a change in pull request #6633: [AIRFLOW-2279] Clear
tasks across DAGs if marked by ExternalTaskMarker
URL: https://github.com/apache/airflow/pull/6633#discussion_r364092453
##########
File path: airflow/models/dag.py
##########
@@ -955,6 +993,60 @@ def clear(
if only_running:
tis = tis.filter(TI.state == State.RUNNING)
+ if include_subdags:
+ from airflow.sensors.external_task_sensor import ExternalTaskMarker
+
+ # Recursively find external tasks indicated by ExternalTaskMarker
+ instances = tis.all()
+ for ti in instances:
+ if ti.operator == ExternalTaskMarker.__name__:
+ task = self.get_task(ti.task_id)
+
+ if recursion_depth == 0:
+ # Maximum recursion depth allowed is the
recursion_depth of the first
+ # ExternalTaskMarker in the tasks to be cleared.
+ max_recursion_depth = task.recursion_depth
+
+ if recursion_depth + 1 > max_recursion_depth:
+ # Prevent cycles or accidents.
+ raise AirflowException("Maximum recursion depth {}
reached for {} {}. "
+ "Attempted to clear too many
tasks "
+ "or there may be a cyclic
dependency."
+ .format(max_recursion_depth,
+
ExternalTaskMarker.__name__, task.task_id))
+
+ instance = TaskInstance(task=task,
execution_date=ti.execution_date)
Review comment:
You are right it's cleaner to call `ti.render_template()` (after setting
`ti.task` to task).
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services