def reload(self, client=None): """API call: sync local subscription configuration via a GET request See https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions/get :attr:`ack_deadline` and :attr:`push_endpoint` might never have been set locally, or might have been updated by another client. This method fetches their values from the server. Example: .. literalinclude:: pubsub_snippets.py :start-after: [START subscription_reload] :end-before: [END subscription_reload] :type client: :class:`~google.cloud.pubsub.client.Client` or ``NoneType`` :param client: the client to use. If not passed, falls back to the ``client`` stored on the current subscription's topic. """ client = self._require_client(client) api = client.subscriber_api data = api.subscription_get(self.full_name) self.ack_deadline = data.get('ackDeadlineSeconds') push_config = data.get('pushConfig', {}) self.push_endpoint = push_config.get('pushEndpoint') if self.topic is None and 'topic' in data: topic_name = topic_name_from_path(data['topic'], client.project) self.topic = client.topic(topic_name)
def from_api_repr(cls, resource, client, topics=None): """Factory: construct a topic given its API representation :type resource: dict :param resource: topic resource representation returned from the API. :type client: :class:`google.cloud.pubsub.client.Client` :param client: Client which holds credentials and project configuration for a topic. :type topics: dict :param topics: (Optional) A mapping of topic names -> topics. If not passed, the subscription will have a newly-created topic. :rtype: :class:`google.cloud.pubsub.subscription.Subscription` :returns: Subscription parsed from ``resource``. """ if topics is None: topics = {} topic_path = resource['topic'] if topic_path == cls._DELETED_TOPIC_PATH: topic = None else: topic = topics.get(topic_path) if topic is None: # NOTE: This duplicates behavior from Topic.from_api_repr to # avoid an import cycle. topic_name = topic_name_from_path(topic_path, client.project) topic = topics[topic_path] = client.topic(topic_name) _, _, _, name = resource['name'].split('/') ack_deadline = resource.get('ackDeadlineSeconds') push_config = resource.get('pushConfig', {}) push_endpoint = push_config.get('pushEndpoint') retain_acked_messages = resource.get('retainAckedMessages') resource_duration = resource.get('duration', {}) message_retention_duration = datetime.timedelta( seconds=resource_duration.get('seconds', 0), microseconds=resource_duration.get('nanos', 0) / 1000) if topic is None: return cls(name, ack_deadline=ack_deadline, push_endpoint=push_endpoint, retain_acked_messages=retain_acked_messages, message_retention_duration=message_retention_duration, client=client) return cls(name, topic=topic, ack_deadline=ack_deadline, push_endpoint=push_endpoint, retain_acked_messages=retain_acked_messages, message_retention_duration=message_retention_duration)
def from_api_repr(cls, resource, client): """Factory: construct a topic given its API representation :type resource: dict :param resource: topic resource representation returned from the API :type client: :class:`google.cloud.pubsub.client.Client` :param client: Client which holds credentials and project configuration for the topic. :rtype: :class:`google.cloud.pubsub.topic.Topic` :returns: Topic parsed from ``resource``. :raises: :class:`ValueError` if ``client`` is not ``None`` and the project from the resource does not agree with the project from the client. """ topic_name = topic_name_from_path(resource['name'], client.project) return cls(topic_name, client=client)
def from_api_repr(cls, resource, client, topics=None): """Factory: construct a topic given its API representation :type resource: dict :param resource: topic resource representation returned from the API. :type client: :class:`google.cloud.pubsub.client.Client` :param client: Client which holds credentials and project configuration for a topic. :type topics: dict :param topics: (Optional) A mapping of topic names -> topics. If not passed, the subscription will have a newly-created topic. :rtype: :class:`google.cloud.pubsub.subscription.Subscription` :returns: Subscription parsed from ``resource``. """ if topics is None: topics = {} topic_path = resource["topic"] if topic_path == cls._DELETED_TOPIC_PATH: topic = None else: topic = topics.get(topic_path) if topic is None: # NOTE: This duplicates behavior from Topic.from_api_repr to # avoid an import cycle. topic_name = topic_name_from_path(topic_path, client.project) topic = topics[topic_path] = client.topic(topic_name) _, _, _, name = resource["name"].split("/") ack_deadline = resource.get("ackDeadlineSeconds") push_config = resource.get("pushConfig", {}) push_endpoint = push_config.get("pushEndpoint") if topic is None: return cls(name, ack_deadline=ack_deadline, push_endpoint=push_endpoint, client=client) return cls(name, topic, ack_deadline, push_endpoint)
def from_api_repr(cls, resource, client, topics=None): """Factory: construct a subscription given its API representation :type resource: dict :param resource: snapshot resource representation returned from the API. :type client: :class:`google.cloud.pubsub.client.Client` :param client: Client which holds credentials and project configuration. :type subscriptions: dict :param subscriptions: (Optional) A Subscription to which this snapshot belongs. If not passed, the subscription will have a newly-created subscription. Must have the same topic as the snapshot. :rtype: :class:`google.cloud.pubsub.subscription.Subscription` :returns: Subscription parsed from ``resource``. """ if topics is None: topics = {} topic_path = resource['topic'] if topic_path == cls._DELETED_TOPIC_PATH: topic = None else: topic = topics.get(topic_path) if topic is None: # NOTE: This duplicates behavior from Topic.from_api_repr to # avoid an import cycle. topic_name = topic_name_from_path(topic_path, client.project) topic = topics[topic_path] = client.topic(topic_name) _, _, _, name = resource['name'].split('/') if topic is None: return cls(name, client=client) return cls(name, topic=topic)
def _callFUT(self, path, project): from google.cloud.pubsub._helpers import topic_name_from_path return topic_name_from_path(path, project)
def _call_fut(self, path, project): from google.cloud.pubsub._helpers import topic_name_from_path return topic_name_from_path(path, project)