Ejemplo n.º 1
0
 def test_schedule_dag_fake_scheduled_previous(self):
     """
     Test scheduling a dag where there is a prior DagRun
     which has the same run_id as the next run should have
     """
     delta = timedelta(hours=1)
     dag = DAG(TEST_DAG_ID+'test_schedule_dag_fake_scheduled_previous',
             schedule_interval=delta,
             start_date=DEFAULT_DATE)
     dag.tasks = [models.BaseOperator(task_id="faketastic",
         owner='Also fake',
         start_date=DEFAULT_DATE)]
     scheduler = jobs.SchedulerJob(test_mode=True)
     trigger = models.DagRun(
                 dag_id=dag.dag_id,
                 run_id=models.DagRun.id_for_date(DEFAULT_DATE),
                 execution_date=DEFAULT_DATE,
                 state=utils.State.SUCCESS,
                 external_trigger=True)
     settings.Session().add(trigger)
     settings.Session().commit()
     dag_run = scheduler.schedule_dag(dag)
     assert dag_run is not None
     assert dag_run.dag_id == dag.dag_id
     assert dag_run.run_id is not None
     assert dag_run.run_id != ''
     assert dag_run.execution_date == DEFAULT_DATE+delta, (
             'dag_run.execution_date did not match expectation: {0}'
             .format(dag_run.execution_date))
     assert dag_run.state == models.State.RUNNING
     assert dag_run.external_trigger == False
Ejemplo n.º 2
0
 def test_schedule_dag_fake_scheduled_previous(self):
     """
     Test scheduling a dag where there is a prior DagRun
     which has the same run_id as the next run should have
     """
     delta = timedelta(hours=1)
     dag = DAG(TEST_DAG_ID + 'test_schedule_dag_fake_scheduled_previous',
               schedule_interval=delta,
               start_date=DEFAULT_DATE)
     dag.tasks = [
         models.BaseOperator(task_id="faketastic",
                             owner='Also fake',
                             start_date=DEFAULT_DATE)
     ]
     scheduler = jobs.SchedulerJob(test_mode=True)
     trigger = models.DagRun(dag_id=dag.dag_id,
                             run_id=models.DagRun.id_for_date(DEFAULT_DATE),
                             execution_date=DEFAULT_DATE,
                             state=utils.State.SUCCESS,
                             external_trigger=True)
     settings.Session().add(trigger)
     settings.Session().commit()
     dag_run = scheduler.schedule_dag(dag)
     assert dag_run is not None
     assert dag_run.dag_id == dag.dag_id
     assert dag_run.run_id is not None
     assert dag_run.run_id != ''
     assert dag_run.execution_date == DEFAULT_DATE + delta, (
         'dag_run.execution_date did not match expectation: {0}'.format(
             dag_run.execution_date))
     assert dag_run.state == models.State.RUNNING
     assert dag_run.external_trigger == False
Ejemplo n.º 3
0
    def test_schedule_dag_once(self):
        """
        Tests scheduling a dag scheduled for @once - should be scheduled the first time
        it is called, and not scheduled the second.
        """
        dag = DAG(TEST_DAG_ID+'test_schedule_dag_once')
        dag.schedule_interval = '@once'
        dag.tasks = [models.BaseOperator(task_id="faketastic", owner='Also fake',
            start_date=datetime(2015, 1, 2, 0, 0))]
        dag_run = jobs.SchedulerJob(test_mode=True).schedule_dag(dag)
        dag_run2 = jobs.SchedulerJob(test_mode=True).schedule_dag(dag)

        assert dag_run is not None
        assert dag_run2 is None
Ejemplo n.º 4
0
    def test_schedule_dag_once(self):
        """
        Tests scheduling a dag scheduled for @once - should be scheduled the first time
        it is called, and not scheduled the second.
        """
        dag = DAG(TEST_DAG_ID+'test_schedule_dag_once')
        dag.schedule_interval = '@once'
        dag.tasks = [models.BaseOperator(task_id="faketastic", owner='Also fake',
            start_date=datetime(2015, 1, 2, 0, 0))]
        dag_run = jobs.SchedulerJob(test_mode=True).schedule_dag(dag)
        dag_run2 = jobs.SchedulerJob(test_mode=True).schedule_dag(dag)

        assert dag_run is not None
        assert dag_run2 is None
Ejemplo n.º 5
0
 def test_schedule_dag_no_previous_runs(self):
     """
     Tests scheduling a dag with no previous runs
     """
     dag = DAG(TEST_DAG_ID+'test_schedule_dag_no_previous_runs')
     dag.tasks = [models.BaseOperator(task_id="faketastic", owner='Also fake',
         start_date=datetime(2015, 1, 2, 0, 0))]
     dag_run = jobs.SchedulerJob(test_mode=True).schedule_dag(dag)
     assert dag_run is not None
     assert dag_run.dag_id == dag.dag_id
     assert dag_run.run_id is not None
     assert dag_run.run_id != ''
     assert dag_run.execution_date == datetime(2015, 1, 2, 0, 0), (
             'dag_run.execution_date did not match expectation: {0}'
             .format(dag_run.execution_date))
     assert dag_run.state == models.State.RUNNING
     assert dag_run.external_trigger == False
Ejemplo n.º 6
0
 def test_schedule_dag_no_previous_runs(self):
     """
     Tests scheduling a dag with no previous runs
     """
     dag = DAG(TEST_DAG_ID+'test_schedule_dag_no_previous_runs')
     dag.tasks = [models.BaseOperator(task_id="faketastic", owner='Also fake',
         start_date=datetime(2015, 1, 2, 0, 0))]
     dag_run = jobs.SchedulerJob(test_mode=True).schedule_dag(dag)
     assert dag_run is not None
     assert dag_run.dag_id == dag.dag_id
     assert dag_run.run_id is not None
     assert dag_run.run_id != ''
     assert dag_run.execution_date == datetime(2015, 1, 2, 0, 0), (
             'dag_run.execution_date did not match expectation: {0}'
             .format(dag_run.execution_date))
     assert dag_run.state == models.State.RUNNING
     assert dag_run.external_trigger == False