zhongjiajie commented on a change in pull request #6342: [AIRFLOW-5662] fix 
incorrect naming and batch db call for scheduler metrics
URL: https://github.com/apache/airflow/pull/6342#discussion_r404749940
 
 

 ##########
 File path: airflow/models/pool.py
 ##########
 @@ -62,6 +71,45 @@ def get_default_pool(session=None):
         """
         return Pool.get_pool(Pool.DEFAULT_POOL_NAME, session=session)
 
+    @staticmethod
+    @provide_session
+    def slots_stats(session=None) -> Dict[str, PoolStats]:
+        from airflow.models.taskinstance import TaskInstance  # Avoid circular 
import
+
+        pools: Dict[str, PoolStats] = {}
+
+        pool_rows: Iterable[Tuple[str, int]] = session.query(Pool.pool, 
Pool.slots).all()
+        for (pool_name, total_slots) in pool_rows:
+            pools[pool_name] = PoolStats({
+                "total": total_slots,
+                State.RUNNING: 0,
+                State.QUEUED: 0,
+            })
+
+        state_count = (
+            session.query(TaskInstance.pool, TaskInstance.state, func.count())
+            .filter(TaskInstance.state.in_(list(EXECUTION_STATES)))
+            .group_by(TaskInstance.pool, TaskInstance.state)
+        ).all()
+
+        # calculate queued and used metrics
+        for (pool_name, state, count) in state_count:
+            pool = pools.get(pool_name)
+            if not pool:
+                continue
+            if state == State.QUEUED or state == State.RUNNING:
 
 Review comment:
   It's odd here, but I can't find out why

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