Пример #1
0
    def test_run_task(self, mock_hook):
        mock_hook.return_value.run_task.return_value = TEST_TASK
        operator = CloudTasksTaskRunOperator(location=LOCATION,
                                             queue_name=QUEUE_ID,
                                             task_name=TASK_NAME,
                                             task_id="id")

        result = operator.execute(context=None)

        assert {
            'app_engine_http_request': {
                'body': '',
                'headers': {},
                'http_method': 0,
                'relative_uri': ''
            },
            'dispatch_count': 0,
            'name': '',
            'response_count': 0,
            'view': 0,
        } == result
        mock_hook.assert_called_once_with(
            gcp_conn_id=GCP_CONN_ID,
            impersonation_chain=None,
        )
        mock_hook.return_value.run_task.assert_called_once_with(
            location=LOCATION,
            queue_name=QUEUE_ID,
            task_name=TASK_NAME,
            project_id=None,
            response_view=None,
            retry=None,
            timeout=None,
            metadata=None,
        )
Пример #2
0
 def test_run_task(self, mock_hook):
     mock_hook.return_value.run_task.return_value = mock.MagicMock()
     operator = CloudTasksTaskRunOperator(
         location=LOCATION, queue_name=QUEUE_ID, task_name=TASK_NAME, task_id="id"
     )
     operator.execute(context=None)
     mock_hook.assert_called_once_with(gcp_conn_id=GCP_CONN_ID)
     mock_hook.return_value.run_task.assert_called_once_with(
         location=LOCATION,
         queue_name=QUEUE_ID,
         task_name=TASK_NAME,
         project_id=None,
         response_view=None,
         retry=None,
         timeout=None,
         metadata=None,
     )
Пример #3
0
    def test_run_task(self, mock_hook):
        mock_hook.return_value.run_task.return_value = TEST_TASK
        operator = CloudTasksTaskRunOperator(location=LOCATION,
                                             queue_name=QUEUE_ID,
                                             task_name=TASK_NAME,
                                             task_id="id")

        result = operator.execute(context=None)

        self.assertEqual({'appEngineHttpRequest': {}}, result)
        mock_hook.assert_called_once_with(
            gcp_conn_id=GCP_CONN_ID,
            impersonation_chain=None,
        )
        mock_hook.return_value.run_task.assert_called_once_with(
            location=LOCATION,
            queue_name=QUEUE_ID,
            task_name=TASK_NAME,
            project_id=None,
            response_view=None,
            retry=None,
            timeout=None,
            metadata=None,
        )
Пример #4
0
        task_name=TASK_NAME,
        retry=Retry(maximum=10.0),
        timeout=5,
        task_id="create_task_to_run",
    )

    tasks_get = CloudTasksTaskGetOperator(
        location=LOCATION,
        queue_name=QUEUE_ID,
        task_name=TASK_NAME,
        task_id="tasks_get",
    )

    run_task = CloudTasksTaskRunOperator(
        location=LOCATION,
        queue_name=QUEUE_ID,
        task_name=TASK_NAME,
        task_id="run_task",
    )

    list_tasks = CloudTasksTasksListOperator(location=LOCATION,
                                             queue_name=QUEUE_ID,
                                             task_id="list_tasks")

    delete_task = CloudTasksTaskDeleteOperator(location=LOCATION,
                                               queue_name=QUEUE_ID,
                                               task_name=TASK_NAME,
                                               task_id="delete_task")

    chain(purge_queue, create_task, tasks_get, list_tasks, run_task,
          delete_task, delete_queue)
Пример #5
0
    create_queue = CloudTasksQueueCreateOperator(
        location=LOCATION,
        task_queue=Queue(),
        queue_name=QUEUE_ID,
        retry=Retry(maximum=10.0),
        timeout=5,
        task_id="create_queue",
    )

    create_task_to_run = CloudTasksTaskCreateOperator(
        location=LOCATION,
        queue_name=QUEUE_ID,
        task=TASK,
        task_name=TASK_NAME,
        retry=Retry(maximum=10.0),
        timeout=5,
        task_id="create_task_to_run",
    )

    run_task = CloudTasksTaskRunOperator(
        location=LOCATION,
        queue_name=QUEUE_ID,
        task_name=TASK_NAME,
        retry=Retry(maximum=10.0),
        timeout=5,
        task_id="run_task",
    )

    create_queue >> create_task_to_run >> run_task