You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/10/05 10:22:47 UTC

[GitHub] [airflow] mik-laj commented on a change in pull request #10956: Officially support running more than one scheduler concurrently.

mik-laj commented on a change in pull request #10956:
URL: https://github.com/apache/airflow/pull/10956#discussion_r499494587



##########
File path: airflow/models/dag.py
##########
@@ -1572,6 +1661,21 @@ def bulk_sync_to_db(cls, dags: Collection["DAG"], sync_time=None, session=None):
             session.add(orm_dag)
             orm_dags.append(orm_dag)
 
+        # Get the latest dag run for each existing dag as a single query (avoid n+1 query)
+        most_recent_dag_runs = dict(session.query(DagRun.dag_id, func.max_(DagRun.execution_date)).filter(
+            DagRun.dag_id.in_(existing_dag_ids),
+            or_(
+                DagRun.run_type == DagRunType.BACKFILL_JOB.value,
+                DagRun.run_type == DagRunType.SCHEDULED.value,
+            ),
+        ).group_by(DagRun.dag_id).all())
+
+        num_active_runs = dict(session.query(DagRun.dag_id, func.count('*')).filter(
+            DagRun.dag_id.in_(existing_dag_ids),
+            DagRun.state == State.RUNNING,  # pylint: disable=comparison-with-callable
+            DagRun.external_trigger.is_(False)
+        ).group_by(DagRun.dag_id).all())

Review comment:
       I wonder if it should be done in this method.  This method only talks about data synchronization, not updating other fields.




----------------------------------------------------------------
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:
users@infra.apache.org