def _setup_subscription(self):
"""Creates a subscription if it does not exist."""
subscription_name = pubsub_utils.get_full_subscription_name()
try:
self.client.projects().subscriptions().get(
subscription=subscription_name).execute()
except errors.HttpError as e:
if e.resp.status == 404:
body = {
'topic': pubsub_utils.get_full_topic_name(),
'pushConfig': {
'pushEndpoint': pubsub_utils.get_app_endpoint_url()
}
}
self.client.projects().subscriptions().create(
name=subscription_name, body=body).execute()
else:
logging.exception(e)
raise
评论列表
文章目录