This is an automated email from the ASF dual-hosted git repository. potiuk pushed a commit to branch v1-10-test in repository https://gitbox.apache.org/repos/asf/airflow.git
commit 8a00764f96e49bb6634785a929b8261377deecc4 Author: Xiaodong DENG <[email protected]> AuthorDate: Sat May 2 21:11:18 2020 +0200 Persist start/end date and duration for DummyOperator Task Instance (#8663) Otherwise the behaviour in UI is incorrect Addressing issue https://github.com/apache/airflow/issues/8662 (cherry picked from commit d92e84818e6268fc46cc0f8916bef034319c5e4c) --- airflow/jobs/scheduler_job.py | 2 ++ tests/jobs/test_scheduler_job.py | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/airflow/jobs/scheduler_job.py b/airflow/jobs/scheduler_job.py index e142dc5..9da73b7 100644 --- a/airflow/jobs/scheduler_job.py +++ b/airflow/jobs/scheduler_job.py @@ -1635,6 +1635,8 @@ class SchedulerJob(BaseJob): if isinstance(ti.task, DummyOperator) \ and not ti.task.on_success_callback: ti.state = State.SUCCESS + ti.start_date = ti.end_date = timezone.utcnow() + ti.duration = 0 # Also save this task instance to the DB. self.log.info("Creating / updating %s in ORM", ti) diff --git a/tests/jobs/test_scheduler_job.py b/tests/jobs/test_scheduler_job.py index 2540291..f756e93 100644 --- a/tests/jobs/test_scheduler_job.py +++ b/tests/jobs/test_scheduler_job.py @@ -2895,6 +2895,16 @@ class SchedulerJobTest(unittest.TestCase): ('test_task_on_execute', 'scheduled'), ('test_task_on_success', 'scheduled'), }, {(ti.task_id, ti.state) for ti in tis}) + for state, start_date, end_date, duration in [(ti.state, ti.start_date, ti.end_date, ti.duration) for + ti in tis]: + if state == 'success': + self.assertIsNotNone(start_date) + self.assertIsNotNone(end_date) + self.assertEqual(0.0, duration) + else: + self.assertIsNone(start_date) + self.assertIsNone(end_date) + self.assertIsNone(duration) scheduler_job.process_file(file_path=dag_file, zombies=[]) with create_session() as session: @@ -2908,3 +2918,13 @@ class SchedulerJobTest(unittest.TestCase): ('test_task_on_execute', 'scheduled'), ('test_task_on_success', 'scheduled'), }, {(ti.task_id, ti.state) for ti in tis}) + for state, start_date, end_date, duration in [(ti.state, ti.start_date, ti.end_date, ti.duration) for + ti in tis]: + if state == 'success': + self.assertIsNotNone(start_date) + self.assertIsNotNone(end_date) + self.assertEqual(0.0, duration) + else: + self.assertIsNone(start_date) + self.assertIsNone(end_date) + self.assertIsNone(duration)
