uranusjr commented on a change in pull request #22123:
URL: https://github.com/apache/airflow/pull/22123#discussion_r833890461



##########
File path: airflow/www/views.py
##########
@@ -1961,24 +1976,53 @@ def _clear_dag_tis(
                 dry_run=True,
             )
         except AirflowException as ex:
-            flash(str(ex), 'error')
-            return redirect(origin)
+            return redirect_or_json(origin, return_as_json, msg=str(ex), 
status="error")
 
         if not tis:
-            flash("No task instances to clear", 'error')
-            response = redirect(origin)
+            msg = "No task instances to clear"
+            return redirect_or_json(origin, return_as_json, msg, 
status="error")
         else:
             details = "\n".join(str(t) for t in tis)
 
             response = self.render_template(
                 'airflow/confirm.html',
                 endpoint=None,
-                message="Here's the list of task instances you are about to 
clear:",
+                message="Task instances you are about to clear:",
                 details=details,
             )
 
         return response
 
+    def _clear_dag_run(self, dag, start_date, end_date, recursive=False, 
confirmed=False, only_failed=False):
+        if confirmed:
+            count = dag.clear(
+                start_date=start_date,
+                end_date=end_date,
+                include_subdags=recursive,
+                include_parentdag=recursive,
+                only_failed=only_failed,
+            )
+            return {'status': 'success', 'message': f"{count} task instances 
have been cleared"}
+
+        try:
+            tis = dag.clear(
+                start_date=start_date,
+                end_date=end_date,
+                include_subdags=recursive,
+                include_parentdag=recursive,
+                only_failed=only_failed,
+                dry_run=True,
+            )
+        except AirflowException as ex:
+            return {'status': 'error', 'message': str(ex)}
+
+        if not tis:
+            return {'status': 'error', 'message': "No task instances to clear"}
+        else:
+            details = [str(t) for t in tis]
+
+            return htmlsafe_json_dumps(details, separators=(',', ':'))

Review comment:
       Is this the same as `_clear_dag_tis` but without `flash` and with 
different return values? We can probably combine them if that’s the case.




-- 
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