def test_create_queue(self, mock_hook): mock_hook.return_value.create_queue.return_value = {} operator = CloudTasksQueueCreateOperator(location=LOCATION, task_queue=Queue(), task_id="id") operator.execute(context=None) mock_hook.assert_called_once_with(gcp_conn_id=GCP_CONN_ID) mock_hook.return_value.create_queue.assert_called_once_with( location=LOCATION, task_queue=Queue(), project_id=None, queue_name=None, retry=None, timeout=None, metadata=None, )
def test_create_queue(self, mock_hook): mock_hook.return_value.create_queue.return_value = TEST_QUEUE operator = CloudTasksQueueCreateOperator(location=LOCATION, task_queue=TEST_QUEUE, task_id="id") result = operator.execute(context=None) self.assertEqual({'name': FULL_QUEUE_PATH, 'state': 0}, result) mock_hook.assert_called_once_with( gcp_conn_id=GCP_CONN_ID, impersonation_chain=None, ) mock_hook.return_value.create_queue.assert_called_once_with( location=LOCATION, task_queue=TEST_QUEUE, project_id=None, queue_name=None, retry=None, timeout=None, metadata=None, )
}, "schedule_time": timestamp, } with models.DAG( "example_gcp_tasks", schedule_interval=None, # Override to match your needs start_date=days_ago(1), tags=['example'], ) as dag: # Queue operations create_queue = CloudTasksQueueCreateOperator( location=LOCATION, task_queue=Queue(stackdriver_logging_config=dict(sampling_ratio=0.5)), queue_name=QUEUE_ID, retry=Retry(maximum=10.0), timeout=5, task_id="create_queue", ) delete_queue = CloudTasksQueueDeleteOperator( location=LOCATION, queue_name=QUEUE_ID, task_id="delete_queue", ) resume_queue = CloudTasksQueueResumeOperator( location=LOCATION, queue_name=QUEUE_ID, task_id="resume_queue", )
"body": b"Hello", }, "schedule_time": timestamp, } with models.DAG( "example_gcp_tasks", schedule_interval=None, # Override to match your needs start_date=days_ago(1), tags=['example'], ) 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(