seanmuth commented on code in PR #73689:
URL: https://github.com/apache/airflow/pull/73689#discussion_r4108293049


##########
airflow-core/src/airflow/serialization/definitions/dag.py:
##########
@@ -712,6 +712,24 @@ def create_dagrun(
         if params_dag.deadline:
             self._process_dagrun_deadline_alerts(orm_dagrun, session)
 
+        if state == DagRunState.QUEUED and backfill_id is None and 
self.max_active_runs:
+            num_running = (
+                session.scalar(
+                    select(func.count())
+                    .select_from(DagRun)
+                    .where(DagRun.dag_id == self.dag_id, DagRun.state == 
DagRunState.RUNNING)
+                )
+                or 0
+            )
+            if num_running >= self.max_active_runs:
+                log.info(
+                    "created DagRun will not be scheduled yet, dag is at 
max_active_runs",
+                    dag_id=self.dag_id,
+                    run_id=run_id,
+                    active_runs=num_running,
+                    max_active_runs=self.max_active_runs,
+                )
+

Review Comment:
   agreed. made a helpful function and moved it's invocation to the 3 
call-sites outside of the scheduler loop.



##########
airflow-core/src/airflow/serialization/definitions/dag.py:
##########
@@ -712,6 +712,24 @@ def create_dagrun(
         if params_dag.deadline:
             self._process_dagrun_deadline_alerts(orm_dagrun, session)
 
+        if state == DagRunState.QUEUED and backfill_id is None and 
self.max_active_runs:
+            num_running = (
+                session.scalar(
+                    select(func.count())
+                    .select_from(DagRun)
+                    .where(DagRun.dag_id == self.dag_id, DagRun.state == 
DagRunState.RUNNING)
+                )
+                or 0
+            )
+            if num_running >= self.max_active_runs:
+                log.info(
+                    "created DagRun will not be scheduled yet, dag is at 
max_active_runs",
+                    dag_id=self.dag_id,
+                    run_id=run_id,
+                    active_runs=num_running,
+                    max_active_runs=self.max_active_runs,
+                )
+

Review Comment:
   agreed. made a helpfer function and moved it's invocation to the 3 
call-sites outside of the scheduler loop.



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