seanmuth commented on code in PR #73689:
URL: https://github.com/apache/airflow/pull/73689#discussion_r4124438601
##########
airflow-core/src/airflow/models/dagrun.py:
##########
@@ -744,6 +744,47 @@ def active_runs_of_dags(
query = query.where(cls.run_type != DagRunType.BACKFILL_JOB)
return {dag_id: count for dag_id, count in session.execute(query)}
+ @classmethod
+ @provide_session
+ def log_if_new_run_blocked_by_max_active_runs(
+ cls,
+ *,
+ dag: SerializedDAG,
+ run_id: str,
+ session: Session = NEW_SESSION,
+ ) -> None:
+ """
+ Log if a just-created DagRun will not be scheduled yet because the Dag
is at max_active_runs.
+
+ Meant to be called by request-driven trigger surfaces -- manual
UI/REST-API triggers and
+ TriggerDagRunOperator/CLI (via
:func:`airflow.api.common.trigger_dag.trigger_dag`) -- right
+ after :meth:`SerializedDAG.create_dagrun`. Deliberately not called
from the scheduler's own
+ run-creation call sites: those run every scheduling loop, and the
scheduler already has
+ separate periodic bookkeeping for this
(``_set_exceeds_max_active_runs``) that intentionally
+ only logs once when a Dag *newly* becomes blocked, rather than every
loop. Calling this from
+ there too would turn a one-shot, per-trigger log back into that same
per-loop spam.
+
+ :meta private:
+ """
+ if not dag.max_active_runs:
+ return
+ num_running = (
+ session.scalar(
+ select(func.count())
+ .select_from(cls)
+ .where(cls.dag_id == dag.dag_id, cls.state ==
DagRunState.RUNNING)
Review Comment:
Good catch — you're right, this counted every running run regardless of
`backfill_id`, which doesn't match how the promotion queries actually gate
concurrency. Added `cls.backfill_id.is_(None)` and a test with a running
backfill run present, to lock in the fix — pushed.
---
Drafted-by: Claude Sonnet 5; reviewed by @seanmuth before posting
--
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]