Ejemplo n.º 1
0
    def test_execute(self, mock_hook):
        operator = PubSubDeleteSubscriptionOperator(
            task_id=TASK_ID, project_id=TEST_PROJECT, subscription=TEST_SUBSCRIPTION
        )

        operator.execute(None)
        mock_hook.return_value.delete_subscription.assert_called_once_with(
            project_id=TEST_PROJECT,
            subscription=TEST_SUBSCRIPTION,
            fail_if_not_exists=False,
            retry=None,
            timeout=None,
            metadata=None,
        )
Ejemplo n.º 2
0
                                        bash_command=echo_cmd)
    # [END howto_operator_gcp_pubsub_pull_messages_result]

    # [START howto_operator_gcp_pubsub_publish]
    publish_task = PubSubPublishMessageOperator(
        task_id="publish_task",
        project_id=GCP_PROJECT_ID,
        topic=TOPIC_FOR_SENSOR_DAG,
        messages=[MESSAGE] * 10,
    )
    # [END howto_operator_gcp_pubsub_publish]

    # [START howto_operator_gcp_pubsub_unsubscribe]
    unsubscribe_task = PubSubDeleteSubscriptionOperator(
        task_id="unsubscribe_task",
        project_id=GCP_PROJECT_ID,
        subscription=subscription,
    )
    # [END howto_operator_gcp_pubsub_unsubscribe]

    # [START howto_operator_gcp_pubsub_delete_topic]
    delete_topic = PubSubDeleteTopicOperator(task_id="delete_topic",
                                             topic=TOPIC_FOR_SENSOR_DAG,
                                             project_id=GCP_PROJECT_ID)
    # [END howto_operator_gcp_pubsub_delete_topic]

    create_topic >> subscribe_task >> publish_task
    pull_messages >> pull_messages_result >> unsubscribe_task >> delete_topic

    # Task dependencies created via `XComArgs`:
    #   subscribe_task >> pull_messages
Ejemplo n.º 3
0
    pull_messages_result = BashOperator(
        task_id="pull_messages_result", bash_command=echo_cmd
    )
    # [END howto_operator_gcp_pubsub_pull_messages_result]

    # [START howto_operator_gcp_pubsub_publish]
    publish_task = PubSubPublishMessageOperator(
        task_id="publish_task",
        project_id=GCP_PROJECT_ID,
        topic=TOPIC,
        messages=[MESSAGE, MESSAGE, MESSAGE],
    )
    # [END howto_operator_gcp_pubsub_publish]

    # [START howto_operator_gcp_pubsub_unsubscribe]
    unsubscribe_task = PubSubDeleteSubscriptionOperator(
        task_id="unsubscribe_task",
        project_id=GCP_PROJECT_ID,
        subscription="{{ task_instance.xcom_pull('subscribe_task') }}",
    )
    # [END howto_operator_gcp_pubsub_unsubscribe]

    # [START howto_operator_gcp_pubsub_delete_topic]
    delete_topic = PubSubDeleteTopicOperator(
        task_id="delete_topic", topic=TOPIC, project_id=GCP_PROJECT_ID
    )
    # [END howto_operator_gcp_pubsub_delete_topic]

    create_topic >> subscribe_task >> publish_task
    subscribe_task >> pull_messages >> pull_messages_result >> unsubscribe_task >> delete_topic