uranusjr commented on a change in pull request #17945:
URL: https://github.com/apache/airflow/pull/17945#discussion_r700868168
##########
File path: airflow/models/dagrun.py
##########
@@ -224,6 +224,26 @@ def next_dagruns_to_examine(
query.limit(max_number), of=cls, session=session,
**skip_locked(session=session)
)
+ @classmethod
+ def get_next_queued_dagruns_for_dag(cls, dag_id: str, session: Session,
max_number: Optional[int] = None):
+ """Get queued dagruns for a particular dag to examine"""
+ if max_number is None:
+ max_number = cls.DEFAULT_DAGRUNS_TO_EXAMINE
+ query = (
+ session.query(cls)
+ .filter(cls.dag_id == dag_id, cls.state == State.QUEUED)
+ .order_by(
+ nulls_first(cls.last_scheduling_decision, session=session),
+ cls.execution_date,
+ )
+ )
+ if not settings.ALLOW_FUTURE_EXEC_DATES:
+ query = query.filter(DagRun.execution_date <= func.now())
+
+ return with_row_locks(
+ query.limit(max_number), of=cls, session=session,
**skip_locked(session=session)
+ )
Review comment:
This whole function, especially the `with_row_locks` part, feels much
too specific, and should be directly inlined where it’s used instead of being a
function on DagRun.
--
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]