You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "peloyeje (via GitHub)" <gi...@apache.org> on 2023/09/21 17:35:44 UTC
[GitHub] [airflow] peloyeje opened a new pull request, #34529: Add ability to clear downstream tis in "List Task Instances" view
peloyeje opened a new pull request, #34529:
URL: https://github.com/apache/airflow/pull/34529
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<!--
Thank you for contributing! Please make sure that your code changes
are covered with tests. And in case of new features or big changes
remember to adjust the documentation.
Feel free to ping committers for the review!
In case of an existing issue, reference it using one of the following:
closes: #ISSUE
related: #ISSUE
How to write a good git commit message:
http://chris.beams.io/posts/git-commit/
-->
<!-- Please keep an empty line above the dashes. -->
---
**^ Add meaningful description above**
Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/main/CONTRIBUTING.rst#pull-request-guidelines)** for more information.
In case of fundamental code changes, an Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals)) is needed.
In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
In case of backwards incompatible changes please leave a note in a newsfragment file, named `{pr_number}.significant.rst` or `{issue_number}.significant.rst`, in [newsfragments](https://github.com/apache/airflow/tree/main/newsfragments).
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] peloyeje commented on a diff in pull request #34529: Add ability to clear downstream tis in "List Task Instances" view
Posted by "peloyeje (via GitHub)" <gi...@apache.org>.
peloyeje commented on code in PR #34529:
URL: https://github.com/apache/airflow/pull/34529#discussion_r1333675946
##########
airflow/www/views.py:
##########
@@ -5803,21 +5853,42 @@ def duration_f(self):
@provide_session
@action_logging
def action_clear(self, task_instances, session: Session = NEW_SESSION):
- """Clears the action."""
+ """Clears an arbitrary number of task instances."""
try:
- dag_to_tis = collections.defaultdict(list)
-
- for ti in task_instances:
- dag = get_airflow_app().dag_bag.get_dag(ti.dag_id)
- dag_to_tis[dag].append(ti)
+ count = self._clear_task_instances(
+ task_instances=task_instances, session=session, clear_downstream=False
+ )
+ session.commit()
+ flash(f"{count} task instances have been cleared")
+ except Exception as e:
+ flash(f'Failed to clear task instances: "{e}"', "error")
- for dag, task_instances_list in dag_to_tis.items():
- models.clear_task_instances(task_instances_list, session, dag=dag)
Review Comment:
[4ad02d1](https://github.com/apache/airflow/pull/34529/commits/4ad02d1cd2b594e2262c58c8e63dcfc21ae6874f)
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] hussein-awala commented on a diff in pull request #34529: Add ability to clear downstream tis in "List Task Instances" view
Posted by "hussein-awala (via GitHub)" <gi...@apache.org>.
hussein-awala commented on code in PR #34529:
URL: https://github.com/apache/airflow/pull/34529#discussion_r1333557853
##########
airflow/www/views.py:
##########
@@ -5803,21 +5853,42 @@ def duration_f(self):
@provide_session
@action_logging
def action_clear(self, task_instances, session: Session = NEW_SESSION):
- """Clears the action."""
+ """Clears an arbitrary number of task instances."""
try:
- dag_to_tis = collections.defaultdict(list)
-
- for ti in task_instances:
- dag = get_airflow_app().dag_bag.get_dag(ti.dag_id)
- dag_to_tis[dag].append(ti)
+ count = self._clear_task_instances(
+ task_instances=task_instances, session=session, clear_downstream=False
+ )
+ session.commit()
+ flash(f"{count} task instances have been cleared")
+ except Exception as e:
+ flash(f'Failed to clear task instances: "{e}"', "error")
- for dag, task_instances_list in dag_to_tis.items():
- models.clear_task_instances(task_instances_list, session, dag=dag)
Review Comment:
Using the same method for both actions is beneficial for maintenance. However, I'm curious if this might impact the performance of the clear action. The `clear_task_instances` method is specifically designed to swiftly clear the provided tasks and their corresponding DAG runs. The newly developed methods clear the task instances on a per-(DAG, DAG run) basis.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] peloyeje commented on pull request #34529: Add ability to clear downstream tis in "List Task Instances" view
Posted by "peloyeje (via GitHub)" <gi...@apache.org>.
peloyeje commented on PR #34529:
URL: https://github.com/apache/airflow/pull/34529#issuecomment-1731743358
Just pushed yet another tweaks to the initial implementation so that `models.clear_task_instances` is called only once per DAG and batches DAG run operations; sorry for all these iterations, I've run out of ideas now 😄
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] boring-cyborg[bot] commented on pull request #34529: Add ability to clear downstream tis in "List Task Instances" view
Posted by "boring-cyborg[bot] (via GitHub)" <gi...@apache.org>.
boring-cyborg[bot] commented on PR #34529:
URL: https://github.com/apache/airflow/pull/34529#issuecomment-1731825617
Awesome work, congrats on your first merged pull request! You are invited to check our [Issue Tracker](https://github.com/apache/airflow/issues) for additional contributions.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] hussein-awala merged pull request #34529: Add ability to clear downstream tis in "List Task Instances" view
Posted by "hussein-awala (via GitHub)" <gi...@apache.org>.
hussein-awala merged PR #34529:
URL: https://github.com/apache/airflow/pull/34529
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] peloyeje commented on pull request #34529: Add ability to clear downstream tis in "List Task Instances" view
Posted by "peloyeje (via GitHub)" <gi...@apache.org>.
peloyeje commented on PR #34529:
URL: https://github.com/apache/airflow/pull/34529#issuecomment-1731911432
Thanks everyone for your feedback!
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] peloyeje commented on a diff in pull request #34529: Add ability to clear downstream tis in "List Task Instances" view
Posted by "peloyeje (via GitHub)" <gi...@apache.org>.
peloyeje commented on code in PR #34529:
URL: https://github.com/apache/airflow/pull/34529#discussion_r1333611036
##########
airflow/www/views.py:
##########
@@ -5803,21 +5853,42 @@ def duration_f(self):
@provide_session
@action_logging
def action_clear(self, task_instances, session: Session = NEW_SESSION):
- """Clears the action."""
+ """Clears an arbitrary number of task instances."""
try:
- dag_to_tis = collections.defaultdict(list)
-
- for ti in task_instances:
- dag = get_airflow_app().dag_bag.get_dag(ti.dag_id)
- dag_to_tis[dag].append(ti)
+ count = self._clear_task_instances(
+ task_instances=task_instances, session=session, clear_downstream=False
+ )
+ session.commit()
+ flash(f"{count} task instances have been cleared")
+ except Exception as e:
+ flash(f'Failed to clear task instances: "{e}"', "error")
- for dag, task_instances_list in dag_to_tis.items():
- models.clear_task_instances(task_instances_list, session, dag=dag)
Review Comment:
Good point, during dev I tried clearing a bunch of tis and I didn't notice any visible performance regression but that's by no means a benchmark :)
I'll compare both code paths asap
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] peloyeje commented on a diff in pull request #34529: Add ability to clear downstream tis in "List Task Instances" view
Posted by "peloyeje (via GitHub)" <gi...@apache.org>.
peloyeje commented on code in PR #34529:
URL: https://github.com/apache/airflow/pull/34529#discussion_r1333668145
##########
airflow/www/views.py:
##########
@@ -5803,21 +5853,42 @@ def duration_f(self):
@provide_session
@action_logging
def action_clear(self, task_instances, session: Session = NEW_SESSION):
- """Clears the action."""
+ """Clears an arbitrary number of task instances."""
try:
- dag_to_tis = collections.defaultdict(list)
-
- for ti in task_instances:
- dag = get_airflow_app().dag_bag.get_dag(ti.dag_id)
- dag_to_tis[dag].append(ti)
+ count = self._clear_task_instances(
+ task_instances=task_instances, session=session, clear_downstream=False
+ )
+ session.commit()
+ flash(f"{count} task instances have been cleared")
+ except Exception as e:
+ flash(f'Failed to clear task instances: "{e}"', "error")
- for dag, task_instances_list in dag_to_tis.items():
- models.clear_task_instances(task_instances_list, session, dag=dag)
Review Comment:
There's indeed an extra ORM call involved for each dag_id, because dag.clear fetches TIs to clear with `_get_task_instances` before calling `clear_task_instances`. So for the default clear action (without downstream) it seems redundant as TIs are already available to the action handler.
I guess perf hit is maximized when the user clears a large number of TIs across a large number of DAG or DAG runs as you hinted (leads to query amplification)
I'll restore the "quick path" for cases when only selected TIs need to be cleared
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] peloyeje commented on a diff in pull request #34529: Add ability to clear downstream tis in "List Task Instances" view
Posted by "peloyeje (via GitHub)" <gi...@apache.org>.
peloyeje commented on code in PR #34529:
URL: https://github.com/apache/airflow/pull/34529#discussion_r1333675946
##########
airflow/www/views.py:
##########
@@ -5803,21 +5853,42 @@ def duration_f(self):
@provide_session
@action_logging
def action_clear(self, task_instances, session: Session = NEW_SESSION):
- """Clears the action."""
+ """Clears an arbitrary number of task instances."""
try:
- dag_to_tis = collections.defaultdict(list)
-
- for ti in task_instances:
- dag = get_airflow_app().dag_bag.get_dag(ti.dag_id)
- dag_to_tis[dag].append(ti)
+ count = self._clear_task_instances(
+ task_instances=task_instances, session=session, clear_downstream=False
+ )
+ session.commit()
+ flash(f"{count} task instances have been cleared")
+ except Exception as e:
+ flash(f'Failed to clear task instances: "{e}"', "error")
- for dag, task_instances_list in dag_to_tis.items():
- models.clear_task_instances(task_instances_list, session, dag=dag)
Review Comment:
[3977962](https://github.com/apache/airflow/pull/34529/commits/3977962dd471dbd4d69be57787caadde32419a1f)
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] SamWheating commented on a diff in pull request #34529: Add ability to clear downstream tis in "List Task Instances" view
Posted by "SamWheating (via GitHub)" <gi...@apache.org>.
SamWheating commented on code in PR #34529:
URL: https://github.com/apache/airflow/pull/34529#discussion_r1333530895
##########
airflow/www/views.py:
##########
@@ -5803,21 +5853,42 @@ def duration_f(self):
@provide_session
@action_logging
def action_clear(self, task_instances, session: Session = NEW_SESSION):
- """Clears the action."""
+ """Clears an arbitrary number of task instances."""
try:
- dag_to_tis = collections.defaultdict(list)
-
- for ti in task_instances:
- dag = get_airflow_app().dag_bag.get_dag(ti.dag_id)
- dag_to_tis[dag].append(ti)
+ count = self._clear_task_instances(
+ task_instances=task_instances, session=session, clear_downstream=False
+ )
+ session.commit()
+ flash(f"{count} task instances have been cleared")
Review Comment:
Thoughts on something like:
```suggestion
flash(f"{count} task instance{'s have' if count > 1 else ' has'} been cleared")
```
In order to read as `1 task instance has been cleared` / `4 task instances have been cleared`?
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] peloyeje commented on a diff in pull request #34529: Add ability to clear downstream tis in "List Task Instances" view
Posted by "peloyeje (via GitHub)" <gi...@apache.org>.
peloyeje commented on code in PR #34529:
URL: https://github.com/apache/airflow/pull/34529#discussion_r1334603444
##########
airflow/www/views.py:
##########
@@ -5803,21 +5859,42 @@ def duration_f(self):
@provide_session
@action_logging
def action_clear(self, task_instances, session: Session = NEW_SESSION):
- """Clears the action."""
+ """Clears an arbitrary number of task instances."""
try:
- dag_to_tis = collections.defaultdict(list)
-
- for ti in task_instances:
- dag = get_airflow_app().dag_bag.get_dag(ti.dag_id)
- dag_to_tis[dag].append(ti)
+ count = self._clear_task_instances(
+ task_instances=task_instances, session=session, clear_downstream=False
+ )
+ session.commit()
+ flash(f"{count} task instances have been cleared")
+ except Exception as e:
+ flash(f'Failed to clear task instances: "{e}"', "error")
- for dag, task_instances_list in dag_to_tis.items():
- models.clear_task_instances(task_instances_list, session, dag=dag)
+ self.update_redirect()
+ return redirect(self.get_redirect())
+ @action(
+ "clear_downstream",
+ lazy_gettext("Clear (including downstream tasks)"),
+ lazy_gettext(
+ "Are you sure you want to clear the state of the selected task"
+ " instance(s) and all their downstream dependencie(s), and set their dagruns to the QUEUED state?"
Review Comment:
Agreed, this was not great! Thanks
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] hussein-awala commented on a diff in pull request #34529: Add ability to clear downstream tis in "List Task Instances" view
Posted by "hussein-awala (via GitHub)" <gi...@apache.org>.
hussein-awala commented on code in PR #34529:
URL: https://github.com/apache/airflow/pull/34529#discussion_r1334643018
##########
airflow/www/views.py:
##########
@@ -31,7 +31,16 @@
from collections import defaultdict
from functools import cached_property, wraps
from json import JSONDecodeError
-from typing import TYPE_CHECKING, Any, Callable, Collection, Iterator, Mapping, MutableMapping, Sequence
+from typing import (
+ TYPE_CHECKING,
+ Any,
+ Callable,
+ Collection,
+ Iterator,
+ Mapping,
+ MutableMapping,
+ Sequence,
+)
Review Comment:
This could be related to a change which you reverted
```suggestion
from typing import TYPE_CHECKING, Any, Callable, Collection, Iterator, Mapping, MutableMapping, Sequence
```
##########
airflow/www/views.py:
##########
@@ -5793,6 +5803,68 @@ def duration_f(self):
"duration": duration_f,
}
+ def _clear_task_instances(
+ self, task_instances: list[TaskInstance], session: Session, clear_downstream: bool = False
+ ) -> tuple[int, int]:
+ """
+ Clears task instances, optionally including their downstream dependencies.
+
+ :param task_instances: list of TIs to clear
+ :param clear_downstream: should downstream task instances be cleared as well?
+
+ :return: a tuple with:
+ - count of cleared task instances actually selected by the user
+ - count of downstream task instances that were additionally cleared
+ """
+ cleared_tis_count = 0
+ cleared_downstream_tis_count = 0
+
+ # Group TIs by dag id in order to call `get_dag` only once per dag
+ tis_grouped_by_dag_id = itertools.groupby(task_instances, lambda ti: ti.dag_id)
+
+ for dag_id, dag_tis in tis_grouped_by_dag_id:
+ dag = get_airflow_app().dag_bag.get_dag(dag_id)
+
+ tis_to_clear = list(dag_tis)
+ downstream_tis_to_clear = []
+
+ if clear_downstream:
+ tis_to_clear_grouped_by_dag_run = itertools.groupby(tis_to_clear, lambda ti: ti.dag_run)
+
+ for dag_run, dag_run_tis in tis_to_clear_grouped_by_dag_run:
+ # Determine tasks that are downstream of the cleared TIs and fetch associated TIs
+ # This has to be run for each dag run because the user may clear different TIs across runs
+ task_ids_to_clear = [ti.task_id for ti in dag_run_tis]
+
+ partial_dag = dag.partial_subset(
+ task_ids_or_regex=task_ids_to_clear, include_downstream=True, include_upstream=False
+ )
+
+ downstream_task_ids_to_clear = [
+ task_id for task_id in partial_dag.task_dict if task_id not in task_ids_to_clear
+ ]
+
+ # dag.clear returns TIs when in dry run mode
Review Comment:
:+1:
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] pierrejeambrun commented on a diff in pull request #34529: Add ability to clear downstream tis in "List Task Instances" view
Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #34529:
URL: https://github.com/apache/airflow/pull/34529#discussion_r1334371070
##########
airflow/www/views.py:
##########
@@ -5803,21 +5859,42 @@ def duration_f(self):
@provide_session
@action_logging
def action_clear(self, task_instances, session: Session = NEW_SESSION):
- """Clears the action."""
+ """Clears an arbitrary number of task instances."""
try:
- dag_to_tis = collections.defaultdict(list)
-
- for ti in task_instances:
- dag = get_airflow_app().dag_bag.get_dag(ti.dag_id)
- dag_to_tis[dag].append(ti)
+ count = self._clear_task_instances(
+ task_instances=task_instances, session=session, clear_downstream=False
+ )
+ session.commit()
+ flash(f"{count} task instances have been cleared")
+ except Exception as e:
+ flash(f'Failed to clear task instances: "{e}"', "error")
- for dag, task_instances_list in dag_to_tis.items():
- models.clear_task_instances(task_instances_list, session, dag=dag)
+ self.update_redirect()
+ return redirect(self.get_redirect())
+ @action(
+ "clear_downstream",
+ lazy_gettext("Clear (including downstream tasks)"),
+ lazy_gettext(
+ "Are you sure you want to clear the state of the selected task"
+ " instance(s) and all their downstream dependencie(s), and set their dagruns to the QUEUED state?"
Review Comment:
singular should be `dependency`, also avoid adding to the wordlist `dependencie` that is mostly a typo. I wouldn't bother and put `dependencies` (always). 1 task can have multiple dependencies, seems fine
##########
tests/www/views/test_views_tasks.py:
##########
@@ -857,6 +859,63 @@ def test_task_instance_clear(session, request, client_fixture, should_succeed):
assert state == (State.NONE if should_succeed else initial_state)
+def test_task_instance_clear_downstream(session, admin_client, dag_maker):
+ """Ensures clearing a task instance clears its downstream dependencies exclusively"""
+ with dag_maker(
+ dag_id="test_dag_id",
+ serialized=True,
+ session=session,
+ start_date=pendulum.DateTime(2023, 1, 1, 0, 0, 0, tzinfo=pendulum.UTC),
+ ):
+ EmptyOperator(task_id="task_1") >> EmptyOperator(task_id="task_2")
+ EmptyOperator(task_id="task_3")
+
+ run1 = dag_maker.create_dagrun(
+ run_id="run_1",
+ state=DagRunState.SUCCESS,
+ run_type=DagRunType.SCHEDULED,
+ execution_date=dag_maker.dag.start_date,
+ start_date=dag_maker.dag.start_date,
+ session=session,
+ )
+
+ run2 = dag_maker.create_dagrun(
+ run_id="run_2",
+ state=DagRunState.SUCCESS,
+ run_type=DagRunType.SCHEDULED,
+ execution_date=dag_maker.dag.start_date.add(days=1),
+ start_date=dag_maker.dag.start_date.add(days=1),
+ session=session,
+ )
+
+ for run in (run1, run2):
+ for ti in run.task_instances:
+ ti.state = State.SUCCESS
+
+ # Clear task_1 from dag run 1
+ run1_ti1 = run1.get_task_instance(task_id="task_1")
+ rowid = _get_appbuilder_pk_string(TaskInstanceModelView, run1_ti1)
+ resp = admin_client.post(
+ "/taskinstance/action_post",
+ data={"action": "clear_downstream", "rowid": rowid},
+ follow_redirects=True,
+ )
+ assert resp.status_code == 200
+
+ # Assert that task_2 of dag run 1 is cleared, but task_3 is left untouched
Review Comment:
```suggestion
# Assert that task_1 and task_2 of dag run 1 are cleared, but task_3 is left untouched
```
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] pierrejeambrun commented on a diff in pull request #34529: Add ability to clear downstream tis in "List Task Instances" view
Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #34529:
URL: https://github.com/apache/airflow/pull/34529#discussion_r1334371070
##########
airflow/www/views.py:
##########
@@ -5803,21 +5859,42 @@ def duration_f(self):
@provide_session
@action_logging
def action_clear(self, task_instances, session: Session = NEW_SESSION):
- """Clears the action."""
+ """Clears an arbitrary number of task instances."""
try:
- dag_to_tis = collections.defaultdict(list)
-
- for ti in task_instances:
- dag = get_airflow_app().dag_bag.get_dag(ti.dag_id)
- dag_to_tis[dag].append(ti)
+ count = self._clear_task_instances(
+ task_instances=task_instances, session=session, clear_downstream=False
+ )
+ session.commit()
+ flash(f"{count} task instances have been cleared")
+ except Exception as e:
+ flash(f'Failed to clear task instances: "{e}"', "error")
- for dag, task_instances_list in dag_to_tis.items():
- models.clear_task_instances(task_instances_list, session, dag=dag)
+ self.update_redirect()
+ return redirect(self.get_redirect())
+ @action(
+ "clear_downstream",
+ lazy_gettext("Clear (including downstream tasks)"),
+ lazy_gettext(
+ "Are you sure you want to clear the state of the selected task"
+ " instance(s) and all their downstream dependencie(s), and set their dagruns to the QUEUED state?"
Review Comment:
singular should be `dependency`, also avoid adding to the wordlist `dependencie` that would mostly allow typo. I wouldn't bother and put `dependencies` (always). 1 task can have multiple dependencies, seems fine
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] peloyeje commented on a diff in pull request #34529: Add ability to clear downstream tis in "List Task Instances" view
Posted by "peloyeje (via GitHub)" <gi...@apache.org>.
peloyeje commented on code in PR #34529:
URL: https://github.com/apache/airflow/pull/34529#discussion_r1333607409
##########
airflow/www/views.py:
##########
@@ -5803,21 +5853,42 @@ def duration_f(self):
@provide_session
@action_logging
def action_clear(self, task_instances, session: Session = NEW_SESSION):
- """Clears the action."""
+ """Clears an arbitrary number of task instances."""
try:
- dag_to_tis = collections.defaultdict(list)
-
- for ti in task_instances:
- dag = get_airflow_app().dag_bag.get_dag(ti.dag_id)
- dag_to_tis[dag].append(ti)
+ count = self._clear_task_instances(
+ task_instances=task_instances, session=session, clear_downstream=False
+ )
+ session.commit()
+ flash(f"{count} task instances have been cleared")
Review Comment:
Sure, good idea!
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [airflow] hussein-awala commented on pull request #34529: Add ability to clear downstream tis in "List Task Instances" view
Posted by "hussein-awala (via GitHub)" <gi...@apache.org>.
hussein-awala commented on PR #34529:
URL: https://github.com/apache/airflow/pull/34529#issuecomment-1731827692
Congrats Jean-Eudes on your first commit :tada:
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org