josh-fell commented on code in PR #25436:
URL: https://github.com/apache/airflow/pull/25436#discussion_r937921158
##########
airflow/providers/microsoft/azure/operators/asb.py:
##########
@@ -467,3 +588,44 @@ def execute(self, context: "Context") -> None:
# delete subscription with name
hook.delete_subscription(self.subscription_name, self.topic_name)
+
+
+class AzureServiceBusTopicDeleteOperator(BaseOperator):
+ """
+ Deletes the topic in the Azure Service Bus namespace
+
+ .. seealso::
+ For more information on how to use this operator, take a look at the
guide:
+ :ref:`howto/operator:AzureServiceBusTopicDeleteOperator`
+
+ :param topic_name: Name of the topic to be deleted.
+ :param azure_service_bus_conn_id: Reference to the
+ :ref:`Azure Service Bus connection
<howto/connection:azure_service_bus>`.
+ """
+
+ template_fields: Sequence[str] = ("topic_name",)
+ ui_color = "#e4f0e8"
+
+ def __init__(
+ self,
+ *,
+ topic_name: str,
+ azure_service_bus_conn_id: str = 'azure_service_bus_default',
+ **kwargs,
+ ) -> None:
+ super().__init__(**kwargs)
+ self.topic_name = topic_name
+ self.azure_service_bus_conn_id = azure_service_bus_conn_id
+
+ def execute(self, context: "Context") -> None:
+ """Delete topic in Service Bus namespace, by connecting to Service Bus
Admin client"""
+ if self.topic_name is None:
+ raise TypeError("Topic name cannot be None.")
+ hook =
AdminClientHook(azure_service_bus_conn_id=self.azure_service_bus_conn_id)
+
+ with hook.get_conn() as service_mgmt_conn:
+ topic_properties = service_mgmt_conn.get_topic(self.topic_name)
+ if topic_properties and topic_properties.name == self.topic_name:
+ service_mgmt_conn.delete_topic(self.topic_name)
+ else:
+ self.log.info("Topic does not exists")
Review Comment:
```suggestion
self.log.info("Topic %s does not exist.", self.topic_name)
```
Minor suggestion to add the name as well. Might be good to see it especially
if the `topic_name` is dynamically generated.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]