Usiel commented on code in PR #32709:
URL: https://github.com/apache/airflow/pull/32709#discussion_r1273029509


##########
airflow/models/pool.py:
##########
@@ -224,15 +236,25 @@ def occupied_slots(self, session: Session = NEW_SESSION) 
-> int:
         """
         from airflow.models.taskinstance import TaskInstance  # Avoid circular 
import
 
+        occupied_states = Pool.get_occupied_states(self.include_deferred)
+
         return int(
             session.scalar(
                 select(func.sum(TaskInstance.pool_slots))
                 .filter(TaskInstance.pool == self.pool)
-                .filter(TaskInstance.state.in_(EXECUTION_STATES))
+                .filter(TaskInstance.state.in_(occupied_states))
             )
             or 0
         )
 
+    @staticmethod
+    def get_occupied_states(include_deferred):
+        if include_deferred:
+            return EXECUTION_STATES | {
+                TaskInstanceState.DEFERRED,
+            }
+        return EXECUTION_STATES

Review Comment:
   Right, that's fixed. Static method was a remnant of a different approach.



##########
airflow/models/pool.py:
##########
@@ -161,21 +163,26 @@ def slots_stats(
         from airflow.models.taskinstance import TaskInstance  # Avoid circular 
import
 
         pools: dict[str, PoolStats] = {}
+        pool_includes_deferred: dict[str, bool] = {}
 
-        query = select(Pool.pool, Pool.slots)
+        query = select(Pool.pool, Pool.slots, Pool.include_deferred)
 
         if lock_rows:
             query = with_row_locks(query, session=session, **nowait(session))
 
         pool_rows = session.execute(query)
-        for (pool_name, total_slots) in pool_rows:
+        for (pool_name, total_slots, includes_deferred) in pool_rows:

Review Comment:
   Done



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