shivaam commented on code in PR #62918:
URL: https://github.com/apache/airflow/pull/62918#discussion_r2998591250
##########
airflow-core/src/airflow/models/dagrun.py:
##########
@@ -1246,6 +1234,26 @@ def recalculate(self) -> _UnfinishedStates:
self.data_interval_start,
self.data_interval_end,
)
+
+ if dag.deadline:
+ if any(
+ DeadlineAlertModel.get_by_id(alert_id,
session).reference_class
+ in SerializedReferenceModels.TYPES.DAGRUN
+ for alert_id in dag.deadline
+ ):
+ if self._state == DagRunState.SUCCESS:
+ # Run succeeded before deadline — prune so they don't
fire.
+ Deadline.prune_deadlines(session=session,
conditions={DagRun.id: self.id})
+ elif self._state == DagRunState.FAILED:
+ # Run failed — immediately fire any pending deadline
callbacks.
+ for deadline in session.scalars(
+ select(Deadline)
+ .join(DagRun)
+ .where(DagRun.id == self.id, ~Deadline.missed)
+ .options(selectinload(Deadline.callback),
selectinload(Deadline.dagrun))
+ ):
+ deadline.handle_miss(session=session)
Review Comment:
Nice fix! One small suggestion on test coverage:
I think it would be nice to also test that handle_miss is called when a dag
is marked as failed before the timeout.
`test_dagrun_failure_does_not_prune_deadlines` verifies that prune_deadlines
is not called on failure, but doesn't verify that handle_miss() is actually
called when recalculate() transitions the run to FAILED which is the main
behavioral change in this PR.
--
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]