def test_create_task(self, mock_hook):
     mock_hook.return_value.create_task.return_value = {}
     operator = CloudTasksTaskCreateOperator(
         location=LOCATION, queue_name=QUEUE_ID, task=Task(), task_id="id"
     )
     operator.execute(context=None)
     mock_hook.assert_called_once_with(gcp_conn_id=GCP_CONN_ID)
     mock_hook.return_value.create_task.assert_called_once_with(
         location=LOCATION,
         queue_name=QUEUE_ID,
         task=Task(),
         project_id=None,
         task_name=None,
         response_view=None,
         retry=None,
         timeout=None,
         metadata=None,
     )
Exemple #2
0
         schedule_interval=None) as dag:

    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