uranusjr commented on code in PR #36935:
URL: https://github.com/apache/airflow/pull/36935#discussion_r1512558868
##########
airflow/models/dagrun.py:
##########
@@ -561,6 +561,45 @@ def fetch_task_instances(
tis = tis.where(TI.task_id.in_(task_ids))
return session.scalars(tis).all()
+ @internal_api_call
+ def _check_last_n_dagruns_failed(self, dag_id,
max_consecutive_failed_dag_runs, session):
+ """Check if last N dags failed."""
+ dag_runs = (
+ session.query(DagRun)
+ .filter(DagRun.dag_id == dag_id)
+ .order_by(DagRun.execution_date.desc())
+ .limit(max_consecutive_failed_dag_runs)
+ .all()
+ )
+
+ """ Marking dag as paused, if needed"""
+ to_be_paused = len(dag_runs) >= max_consecutive_failed_dag_runs and
all(
+ dag_run.state == DagRunState.FAILED for dag_run in dag_runs
+ )
+ if to_be_paused:
+ from airflow.models.dag import DagModel
+
+ self.log.warning(
+ "Pausing DAG %s because last %s DAG runs failed.",
+ self.dag_id,
+ max_consecutive_failed_dag_runs,
+ )
+ filter_query = [
+ DagModel.dag_id == self.dag_id,
+ DagModel.root_dag_id == self.dag_id, # for sub-dags
+ ]
+ session.execute(
+ update(DagModel)
+ .where(or_(*filter_query))
+ .values(is_paused=True)
+ .execution_options(synchronize_session="fetch")
+ )
+ else:
+ self.log.info(
+ "Limit of consecutive DAG failed dag runs is not reached, DAG
%s will not be paused.",
+ self.dag_id,
+ )
Review Comment:
I don’t think this should be `info`; `debug` is probably good enough.
--
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]