kaxil commented on a change in pull request #7489: [AIRFLOW-6869][WIP] Bulk 
fetch DAGRuns for _process_task_instances
URL: https://github.com/apache/airflow/pull/7489#discussion_r382944080
 
 

 ##########
 File path: airflow/jobs/scheduler_job.py
 ##########
 @@ -699,23 +727,30 @@ def _process_dags(self, dagbag, dags, tis_out):
                 self.log.info("Not processing DAG %s since it's paused", 
dag.dag_id)
                 continue
 
-            self.log.info("Processing %s", dag.dag_id)
+            dag_id = dag.dag_id
+            self.log.info("Processing %s", dag_id)
+            dag_runs_for_dag = dag_runs_by_dag_id[dag_id] if dag_id in 
dag_runs_by_dag_id else []
 
             # Only creates DagRun for DAGs that are not subdag since
             # DagRun of subdags are created when SubDagOperator executes.
             if not dag.is_subdag:
                 dag_run = self.create_dag_run(dag)
                 if dag_run:
+                    dag_runs_for_dag.append(dag_run)
                     expected_start_date = 
dag.following_schedule(dag_run.execution_date)
                     if expected_start_date:
                         schedule_delay = dag_run.start_date - 
expected_start_date
                         Stats.timing(
                             
'dagrun.schedule_delay.{dag_id}'.format(dag_id=dag.dag_id),
                             schedule_delay)
-                self.log.info("Created %s", dag_run)
-            self._process_task_instances(dag, tis_out)
-            if check_slas:
-                self.manage_slas(dag)
+                    self.log.info("Created %s", dag_run)
+
+            if dag_runs_for_dag:
+                tis_out.extend(self._process_task_instances(dag, 
dag_runs_for_dag))
+                if check_slas:
+                    self.manage_slas(dag)
 
 Review comment:
   I am thinking of a case where a DagRun is just completed and the Dag (or 
last task) has missed SLA. In which case DagRun won't be in RUNNING state and 
would be filtered in the following check:
   
   ```
   dag_runs = DagRun.find(dag_ids=dag_ids, state=State.RUNNING, session=session)
   ```
   
   And SLAs won't be triggered for such 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

Reply via email to