ashb commented on a change in pull request #4949: [AIRFLOW-1557] Backfill 
should respect pool limit
URL: https://github.com/apache/airflow/pull/4949#discussion_r268110596
 
 

 ##########
 File path: airflow/jobs.py
 ##########
 @@ -2300,8 +2301,33 @@ def _per_task_process(task, key, ti, session=None):
                 self.log.debug('Adding %s to not_ready', ti)
                 ti_status.not_ready.add(key)
 
+            pool_name = self.pool
+            if self.pool:
+                pool = session.query(models.Pool) \
+                    .filter(models.Pool.pool == self.pool) \
+                    .first()
+                if pool is not None:
+                    open_slots = pool.open_slots(session=session)
+                else:
+                    open_slots = 0
+                    self.log.warning(
+                        "Tasks using non-existent pool '%s' will not be 
scheduled",
+                        pool,
+                    )
+            else:
+                open_slots = conf.getint('core', 
'non_pooled_backfill_task_slot_count')
+                pool_name = 'not_pooled'
+
             for task in self.dag.topological_sort():
                 for key, ti in list(ti_status.to_run.items()):
+                    if open_slots <= 0:
+                        self.log.debug(
+                            "Not scheduling since there are %s open slots in 
pool %s",
+                            open_slots, pool_name,
+                        )
+                        break
+                    open_slots -= 1
 
 Review comment:
   I feel that just keeping a count in memory isn't right, and we should check 
the DB for an accurate count of the pool each loop.
   
   I also don't think that breaking out of the loop is the right behaviour - 
this would mean that if you hit the pool limit backfilling just stops, rather 
than waiting for a slot to become free.

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