Exemplo n.º 1
0
    def test_trigger_dagrun(self):
        """Test TriggerDagRunOperator."""
        task = TriggerDagRunOperator(task_id="test_task",
                                     trigger_dag_id=TRIGGERED_DAG_ID,
                                     dag=self.dag)
        task.run(start_date=DEFAULT_DATE,
                 end_date=DEFAULT_DATE,
                 ignore_ti_state=True)

        with create_session() as session:
            dagruns = session.query(DagRun).filter(
                DagRun.dag_id == TRIGGERED_DAG_ID).all()
            self.assertEqual(len(dagruns), 1)
            self.assertTrue(dagruns[0].external_trigger)
Exemplo n.º 2
0
 def test_trigger_dagrun_with_wait_for_completion_true_fail(self):
     """Test TriggerDagRunOperator with wait_for_completion but triggered dag fails."""
     execution_date = DEFAULT_DATE
     task = TriggerDagRunOperator(
         task_id="test_task",
         trigger_dag_id=TRIGGERED_DAG_ID,
         execution_date=execution_date,
         wait_for_completion=True,
         poke_interval=10,
         failed_states=[State.RUNNING],
         dag=self.dag,
     )
     with self.assertRaises(AirflowException):
         task.run(start_date=execution_date, end_date=execution_date)
Exemplo n.º 3
0
    def test_trigger_dagrun_operator_templated_conf(self):
        """Test passing a templated conf to the triggered DagRun."""
        task = TriggerDagRunOperator(
            task_id="test_trigger_dagrun_with_str_execution_date",
            trigger_dag_id=TRIGGERED_DAG_ID,
            conf={"foo": "{{ dag.dag_id }}"},
            dag=self.dag,
        )
        task.run(start_date=DEFAULT_DATE,
                 end_date=DEFAULT_DATE,
                 ignore_ti_state=True)

        with create_session() as session:
            dagruns = session.query(DagRun).filter(
                DagRun.dag_id == TRIGGERED_DAG_ID).all()
            self.assertEqual(len(dagruns), 1)
            self.assertTrue(dagruns[0].conf, {"foo": TEST_DAG_ID})
Exemplo n.º 4
0
    def test_trigger_dagrun_with_wait_for_completion_true(self):
        """Test TriggerDagRunOperator with wait_for_completion."""
        execution_date = DEFAULT_DATE
        task = TriggerDagRunOperator(
            task_id="test_task",
            trigger_dag_id=TRIGGERED_DAG_ID,
            execution_date=execution_date,
            wait_for_completion=True,
            poke_interval=10,
            allowed_states=[State.RUNNING],
            dag=self.dag,
        )
        task.run(start_date=execution_date, end_date=execution_date)

        with create_session() as session:
            dagruns = session.query(DagRun).filter(
                DagRun.dag_id == TRIGGERED_DAG_ID).all()
            self.assertEqual(len(dagruns), 1)
Exemplo n.º 5
0
    def test_trigger_dagrun_with_reset_dag_run_false(self):
        """Test TriggerDagRunOperator with reset_dag_run."""
        execution_date = DEFAULT_DATE
        task = TriggerDagRunOperator(
            task_id="test_task",
            trigger_dag_id=TRIGGERED_DAG_ID,
            execution_date=execution_date,
            reset_dag_run=False,
            dag=self.dag,
        )
        task.run(start_date=execution_date,
                 end_date=execution_date,
                 ignore_ti_state=True)

        with self.assertRaises(DagRunAlreadyExists):
            task.run(start_date=execution_date,
                     end_date=execution_date,
                     ignore_ti_state=True)
Exemplo n.º 6
0
    def test_trigger_dagrun_with_templated_execution_date(self):
        """Test TriggerDagRunOperator with templated execution_date."""
        task = TriggerDagRunOperator(
            task_id="test_trigger_dagrun_with_str_execution_date",
            trigger_dag_id=TRIGGERED_DAG_ID,
            execution_date="{{ execution_date }}",
            dag=self.dag,
        )
        task.run(start_date=DEFAULT_DATE,
                 end_date=DEFAULT_DATE,
                 ignore_ti_state=True)

        with create_session() as session:
            dagruns = session.query(DagRun).filter(
                DagRun.dag_id == TRIGGERED_DAG_ID).all()
            self.assertEqual(len(dagruns), 1)
            self.assertTrue(dagruns[0].external_trigger)
            self.assertEqual(dagruns[0].execution_date, DEFAULT_DATE)
Exemplo n.º 7
0
    def test_trigger_dagrun_with_execution_date(self):
        """Test TriggerDagRunOperator with custom execution_date."""
        utc_now = timezone.utcnow()
        task = TriggerDagRunOperator(
            task_id="test_trigger_dagrun_with_execution_date",
            trigger_dag_id=TRIGGERED_DAG_ID,
            execution_date=utc_now,
            dag=self.dag,
        )
        task.run(start_date=DEFAULT_DATE,
                 end_date=DEFAULT_DATE,
                 ignore_ti_state=True)

        with create_session() as session:
            dagruns = session.query(DagRun).filter(
                DagRun.dag_id == TRIGGERED_DAG_ID).all()
            self.assertEqual(len(dagruns), 1)
            self.assertTrue(dagruns[0].external_trigger)
            self.assertEqual(dagruns[0].execution_date, utc_now)
Exemplo n.º 8
0
    def test_trigger_dagrun_with_reset_dag_run_true(self):
        """Test TriggerDagRunOperator with reset_dag_run."""
        execution_date = DEFAULT_DATE
        task = TriggerDagRunOperator(
            task_id="test_task",
            trigger_dag_id=TRIGGERED_DAG_ID,
            execution_date=execution_date,
            reset_dag_run=True,
            dag=self.dag,
        )
        task.run(start_date=execution_date,
                 end_date=execution_date,
                 ignore_ti_state=True)
        task.run(start_date=execution_date,
                 end_date=execution_date,
                 ignore_ti_state=True)

        with create_session() as session:
            dagruns = session.query(DagRun).filter(
                DagRun.dag_id == TRIGGERED_DAG_ID).all()
            assert len(dagruns) == 1
            assert dagruns[0].external_trigger