dstandish commented on code in PR #46554:
URL: https://github.com/apache/airflow/pull/46554#discussion_r1952703142
##########
airflow/models/backfill.py:
##########
@@ -432,3 +435,31 @@ def _create_backfill(
info,
)
return br
+
+
+def clear_run_if_dagrun_exists(dag, info, reprocess_behavior, backfill_id,
session):
+ from airflow.models import DagRun
+
+ dr = session.scalar(
+ statement=_get_latest_dag_run_row_query(info, session),
+ )
+ if dr:
+ if dr.state in {DagRunState.SUCCESS, DagRunState.FAILED} and
reprocess_behavior in {
+ ReprocessBehavior.COMPLETED,
+ ReprocessBehavior.FAILED,
+ }:
+ dag.clear(
+ run_id=dr.run_id,
+ dag_run_state=DagRunState.QUEUED,
+ session=session,
+ confirm_prompt=False,
+ dry_run=False,
+ )
+ # updating backfill id and run_type in dag_run table
+ update_backfill_id = (
+ update(DagRun)
+ .where(DagRun.logical_date == info.logical_date)
+ .values(backfill_id=backfill_id, run_type=DagRunType.BACKFILL_JOB)
+ )
+ session.execute(update_backfill_id)
Review Comment:
if you clear, then immediately it will be scheduled.
--
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]