ephraimbuddy commented on a change in pull request #16182:
URL: https://github.com/apache/airflow/pull/16182#discussion_r647021778



##########
File path: airflow/jobs/scheduler_job.py
##########
@@ -1417,6 +1420,37 @@ def _clean_tis_without_dagrun(self, session):
                     raise
             guard.commit()
 
+    @provide_session
+    def _missing_dag_file_cleanup(self, session: Session = None):
+        """Fails task instances and DagRuns of DAGs that no longer exist in 
the dag folder"""
+        states_to_check = State.unfinished - frozenset([State.NONE, 
State.SHUTDOWN])
+        tis = session.query(TI).filter(TI.state.in_(states_to_check)).all()
+        missing_dags = {}
+        dag_runs = set()
+        for ti in tis:
+            dag = self.dagbag.dags.get(ti.dag_id, None)
+            if not dag:
+                continue
+            if not os.path.exists(dag.fileloc):

Review comment:
       I have updated this and tested by renaming dags in their files in which 
case the dag file exists but the dag itself no longer exists. The result was 
that the executor sees immediately that the dag_id cannot be found and errors. 
Then reports to the scheduler that the task instance has failed. Here 
immediately, the task instance is failed in the scheduler.  
   
   When the time for running this change reaches and there are still task 
instances not existing anymore which are not failed, it fails them effectively.
   
   Check if the implementation is alright. 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.

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


Reply via email to