r39132 closed pull request #1601: [AIRFLOW-249] Refactor the SLA mechanism
URL: https://github.com/apache/incubator-airflow/pull/1601
This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:
As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):
diff --git a/airflow/jobs.py b/airflow/jobs.py
index 1e583ac41b..d6f32cd52a 100644
--- a/airflow/jobs.py
+++ b/airflow/jobs.py
@@ -258,39 +258,33 @@ def manage_slas(self, dag, session=None):
tasks that should have succeeded in the past hour.
"""
TI = models.TaskInstance
- sq = (
- session
- .query(
- TI.task_id,
- func.max(TI.execution_date).label('max_ti'))
- .filter(TI.dag_id == dag.dag_id)
- .filter(TI.state == State.SUCCESS)
- .filter(TI.task_id.in_(dag.task_ids))
- .group_by(TI.task_id).subquery('sq')
+ SlaMiss = models.SlaMiss
+
+ sla_missed = (
+ session.query(SlaMiss)
+ .filter(SlaMiss.email_sent == 't')
+ .subquery('sla_missed')
)
- max_tis = session.query(TI).filter(
- TI.dag_id == dag.dag_id,
- TI.task_id == sq.c.task_id,
- TI.execution_date == sq.c.max_ti,
- ).all()
+ sq = session.query(TI).outerjoin(
+ sla_missed,
+ sla_missed.c.execution_date == TI.execution_date).filter(
+ sla_missed.c.execution_date == None,
+ TI.dag_id == dag.dag_id,
+ TI.state == State.RUNNING,
+ TI.task_id.in_(dag.task_ids)
+ ).all()
ts = datetime.now()
- SlaMiss = models.SlaMiss
- for ti in max_tis:
+ for ti in sq:
task = dag.get_task(ti.task_id)
- dttm = ti.execution_date
if task.sla:
- dttm = dag.following_schedule(dttm)
- while dttm < datetime.now():
- following_schedule = dag.following_schedule(dttm)
- if following_schedule + task.sla < datetime.now():
- session.merge(models.SlaMiss(
- task_id=ti.task_id,
- dag_id=ti.dag_id,
- execution_date=dttm,
- timestamp=ts))
- dttm = dag.following_schedule(dttm)
+ if ti.start_date + task.sla < ts:
+ session.merge(models.SlaMiss(
+ task_id=ti.task_id,
+ dag_id=ti.dag_id,
+ execution_date=ti.execution_date,
+ timestamp=ts))
session.commit()
slas = (
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services