kaxil commented on a change in pull request #17945:
URL: https://github.com/apache/airflow/pull/17945#discussion_r700919999



##########
File path: airflow/jobs/scheduler_job.py
##########
@@ -970,48 +971,61 @@ def _start_queued_dagruns(
         session: Session,
     ) -> int:
         """Find DagRuns in queued state and decide moving them to running 
state"""
-        dag_runs = self._get_next_dagruns_to_examine(State.QUEUED, session)
-
-        active_runs_of_dags = defaultdict(
-            lambda: 0,
-            session.query(DagRun.dag_id, func.count('*'))
-            .filter(  # We use `list` here because SQLA doesn't accept a set
-                # We use set to avoid duplicate dag_ids
-                DagRun.dag_id.in_(list({dr.dag_id for dr in dag_runs})),
-                DagRun.state == State.RUNNING,
-            )
-            .group_by(DagRun.dag_id)
-            .all(),
+        active_dags = (
+            session.query(DM)
+            .filter(DM.is_active == expression.true(), DM.is_paused == 
expression.false())

Review comment:
       Do you just need count of those DAGs @ephraimbuddy not actual Dag 
Models? If so use func.count:
   
   ```
   session.query(func.count(DM.dag_id).filter(DM.is_active == 
expression.true(), DM.is_paused == expression.false())).scalar()
   ```




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