TobKed commented on a change in pull request #6096: [AIRFLOW-5477] Rewrite
Google PubSub Hook to Google Cloud Python
URL: https://github.com/apache/airflow/pull/6096#discussion_r324701479
##########
File path: airflow/gcp/hooks/pubsub.py
##########
@@ -129,23 +221,39 @@ def delete_topic(self, project: str, topic: str,
fail_if_not_exists: bool = Fals
:param fail_if_not_exists: if set, raise an exception if the topic
does not exist
:type fail_if_not_exists: bool
+ :param retry: (Optional) A retry object used to retry requests.
+ If None is specified, requests will not be retried.
+ :type retry: google.api_core.retry.Retry
+ :param timeout: (Optional) The amount of time, in seconds, to wait for
the request
+ to complete. Note that if retry is specified, the timeout applies
to each
+ individual attempt.
+ :type timeout: float
+ :param metadata: (Optional) Additional metadata that is provided to
the method.
+ :type metadata: Sequence[Tuple[str, str]]]
"""
- service = self.get_conn()
- full_topic = _format_topic(project, topic)
+ assert project is not None
+ publisher = self.get_conn()
+ topic_path = PublisherClient.topic_path(project, topic) # pylint:
disable=no-member
+
+ self.log.info("Deleting topic (path) %s", topic_path)
try:
- service.projects().topics().delete( # pylint: disable=no-member
- topic=full_topic).execute(num_retries=self.num_retries)
- except HttpError as e:
- # Status code 409 indicates that the topic was not found
- if str(e.resp['status']) == '404':
- message = 'Topic does not exist: {}'.format(full_topic)
- self.log.warning(message)
- if fail_if_not_exists:
- raise PubSubException(message)
- else:
- raise PubSubException(
- 'Error deleting topic {}'.format(full_topic), e)
+ # pylint: disable=no-member
+ publisher.delete_topic(
+ topic=topic_path,
+ retry=retry,
+ timeout=timeout,
+ metadata=metadata,
+ )
+ except NotFound:
+ message = 'Topic does not exist: {}'.format(topic_path)
+ self.log.warning(message)
+ if fail_if_not_exists:
+ raise PubSubException(message)
+ except GoogleAPICallError as e:
Review comment:
I've added test.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services