You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/03/01 00:19:43 UTC

[GitHub] [airflow] mik-laj commented on a change in pull request #7597: [AIRFLOW-6497][WIP] Avoid loading DAGs in the main scheduler loop

mik-laj commented on a change in pull request #7597: [AIRFLOW-6497][WIP] Avoid loading DAGs in the main scheduler loop
URL: https://github.com/apache/airflow/pull/7597#discussion_r386065568
 
 

 ##########
 File path: tests/jobs/test_scheduler_job.py
 ##########
 @@ -1015,14 +1012,52 @@ def test_kill_zombies(self, mock_ti_handle_failure):
             session.add(ti)
             session.commit()
 
-            zombies = [SimpleTaskInstance(ti)]
-            dag_file_processor.kill_zombies(dagbag, zombies)
+            requests = [
+                FailureCallbackRequest(
+                    full_filepath="A",
+                    simple_task_instance=SimpleTaskInstance(ti),
+                    msg="Message"
+                )
+            ]
+            dag_file_processor.execute_on_failure_callbacks(dagbag, requests)
             mock_ti_handle_failure.assert_called_once_with(
-                mock.ANY,
+                "Message",
                 conf.getboolean('core', 'unit_test_mode'),
                 mock.ANY
             )
 
+    def test_process_file_should_failure_callback(self):
+        dag_file = os.path.join(
+            os.path.dirname(os.path.realpath(__file__)), '../dags/test_on_failure_callback.py'
+        )
+        dagbag = DagBag(dag_folder=dag_file, include_examples=False)
+        dag_file_processor = DagFileProcessor(dag_ids=[], log=mock.MagicMock())
+        with create_session() as session, NamedTemporaryFile(delete=False) as callback_file:
+            session.query(TaskInstance).delete()
+            dag = dagbag.get_dag('test_om_failure_callback_dag')
+            task = dag.get_task(task_id='test_om_failure_callback_task')
+
+            ti = TaskInstance(task, DEFAULT_DATE, State.RUNNING)
+
+            session.add(ti)
+            session.commit()
+
+            requests = [
+                FailureCallbackRequest(
+                    full_filepath=dag.full_filepath,
+                    simple_task_instance=SimpleTaskInstance(ti),
+                    msg="Message"
+                )
+            ]
+            callback_file.close()
+
+            with mock.patch.dict("os.environ", {"AIRFLOW_CALLBACK_FILE": callback_file.name}):
+                dag_file_processor.process_file(dag_file, requests)
+            with open(callback_file.name) as callback_file2:
+                content = callback_file2.read()
+            self.assertEqual("Callbacck fired", content)
 
 Review comment:
   Done

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services