def _make_txn_selector(self): """Helper for :meth:`read`.""" if self._transaction_id is not None: return TransactionSelector(id=self._transaction_id) if self._read_timestamp: key = "read_timestamp" value = _datetime_to_pb_timestamp(self._read_timestamp) elif self._min_read_timestamp: key = "min_read_timestamp" value = _datetime_to_pb_timestamp(self._min_read_timestamp) elif self._max_staleness: key = "max_staleness" value = _timedelta_to_duration_pb(self._max_staleness) elif self._exact_staleness: key = "exact_staleness" value = _timedelta_to_duration_pb(self._exact_staleness) else: key = "strong" value = True options = TransactionOptions( read_only=TransactionOptions.ReadOnly(**{key: value}) ) if self._multi_use: return TransactionSelector(begin=options) else: return TransactionSelector(single_use=options)
def _make_txn_selector(self): """Helper for :meth:`read`.""" if self._transaction_id is not None: return TransactionSelector(id=self._transaction_id) if self._read_timestamp: key = 'read_timestamp' value = _datetime_to_pb_timestamp(self._read_timestamp) elif self._min_read_timestamp: key = 'min_read_timestamp' value = _datetime_to_pb_timestamp(self._min_read_timestamp) elif self._max_staleness: key = 'max_staleness' value = _timedelta_to_duration_pb(self._max_staleness) elif self._exact_staleness: key = 'exact_staleness' value = _timedelta_to_duration_pb(self._exact_staleness) else: key = 'strong' value = True options = TransactionOptions( read_only=TransactionOptions.ReadOnly(**{key: value})) if self._multi_use: return TransactionSelector(begin=options) else: return TransactionSelector(single_use=options)
def to_pb(self): """Converts the garbage collection rule to a protobuf. :rtype: :class:`.table_v2_pb2.GcRule` :returns: The converted current object. """ max_age = _helpers._timedelta_to_duration_pb(self.max_age) return table_v2_pb2.GcRule(max_age=max_age)
def to_pb(self): """Converts the garbage collection rule to a protobuf. :rtype: :class:`.table_v2_pb2.GcRule` :returns: The converted current object. """ max_age = _helpers._timedelta_to_duration_pb(self.max_age) return table_v2_pb2.GcRule(max_age=max_age)
def _call_fut(self, *args, **kwargs): from google.cloud._helpers import _timedelta_to_duration_pb return _timedelta_to_duration_pb(*args, **kwargs)
def subscription_create(self, subscription_path, topic_path, ack_deadline=None, push_endpoint=None, retain_acked_messages=None, message_retention_duration=None): """API call: create a subscription See https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions/create :type subscription_path: str :param subscription_path: the fully-qualified path of the new subscription, in format ``projects/<PROJECT>/subscriptions/<SUB_NAME>``. :type topic_path: str :param topic_path: the fully-qualified path of the topic being subscribed, in format ``projects/<PROJECT>/topics/<TOPIC_NAME>``. :type ack_deadline: int :param ack_deadline: (Optional) the deadline (in seconds) by which messages pulled from the back-end must be acknowledged. :type push_endpoint: str :param push_endpoint: (Optional) URL to which messages will be pushed by the back-end. If not set, the application must pull messages. :type retain_acked_messages: bool :param retain_acked_messages: (Optional) Whether to retain acked messages. If set, acked messages are retained in the subscription's backlog for a duration indicated by `message_retention_duration`. :type message_retention_duration: :class:`datetime.timedelta` :param message_retention_duration: (Optional) Whether to retain acked messages. If set, acked messages are retained in the subscription's backlog for a duration indicated by `message_retention_duration`. If unset, defaults to 7 days. :rtype: dict :returns: ``Subscription`` resource returned from the API. """ path = '/%s' % (subscription_path, ) resource = {'topic': topic_path} if ack_deadline is not None: resource['ackDeadlineSeconds'] = ack_deadline if push_endpoint is not None: resource['pushConfig'] = {'pushEndpoint': push_endpoint} if retain_acked_messages is not None: resource['retainAckedMessages'] = retain_acked_messages if message_retention_duration is not None: pb = _timedelta_to_duration_pb(message_retention_duration) resource['messageRetentionDuration'] = { 'seconds': pb.seconds, 'nanos': pb.nanos } return self.api_request(method='PUT', path=path, data=resource)
def _call_fut(self, *args, **kwargs): from google.cloud._helpers import _timedelta_to_duration_pb return _timedelta_to_duration_pb(*args, **kwargs)
def subscription_create(self, subscription_path, topic_path, ack_deadline=None, push_endpoint=None, retain_acked_messages=None, message_retention_duration=None): """API call: create a subscription See: https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions/create :type subscription_path: str :param subscription_path: the fully-qualified path of the new subscription, in format ``projects/<PROJECT>/subscriptions/<SUB_NAME>``. :type topic_path: str :param topic_path: the fully-qualified path of the topic being subscribed, in format ``projects/<PROJECT>/topics/<TOPIC_NAME>``. :type ack_deadline: int :param ack_deadline: (Optional) the deadline (in seconds) by which messages pulled from the back-end must be acknowledged. :type push_endpoint: str :param push_endpoint: (Optional) URL to which messages will be pushed by the back-end. If not set, the application must pull messages. :type retain_acked_messages: bool :param retain_acked_messages: (Optional) Whether to retain acked messages. If set, acked messages are retained in the subscription's backlog for a duration indicated by `message_retention_duration`. :type message_retention_duration: :class:`datetime.timedelta` :param message_retention_duration: (Optional) Whether to retain acked messages. If set, acked messages are retained in the subscription's backlog for a duration indicated by `message_retention_duration`. If unset, defaults to 7 days. :rtype: dict :returns: ``Subscription`` resource returned from the API. """ if push_endpoint is not None: push_config = PushConfig(push_endpoint=push_endpoint) else: push_config = None if message_retention_duration is not None: message_retention_duration = _timedelta_to_duration_pb( message_retention_duration) try: sub_pb = self._gax_api.create_subscription( subscription_path, topic_path, push_config=push_config, ack_deadline_seconds=ack_deadline, retain_acked_messages=retain_acked_messages, message_retention_duration=message_retention_duration) except GaxError as exc: if exc_to_code(exc.cause) == StatusCode.FAILED_PRECONDITION: raise Conflict(topic_path) raise return MessageToDict(sub_pb)
def subscription_create(self, subscription_path, topic_path, ack_deadline=None, push_endpoint=None, retain_acked_messages=None, message_retention_duration=None): """API call: create a subscription See: https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.subscriptions/create :type subscription_path: str :param subscription_path: the fully-qualified path of the new subscription, in format ``projects/<PROJECT>/subscriptions/<SUB_NAME>``. :type topic_path: str :param topic_path: the fully-qualified path of the topic being subscribed, in format ``projects/<PROJECT>/topics/<TOPIC_NAME>``. :type ack_deadline: int :param ack_deadline: (Optional) the deadline (in seconds) by which messages pulled from the back-end must be acknowledged. :type push_endpoint: str :param push_endpoint: (Optional) URL to which messages will be pushed by the back-end. If not set, the application must pull messages. :type retain_acked_messages: bool :param retain_acked_messages: (Optional) Whether to retain acked messages. If set, acked messages are retained in the subscription's backlog for a duration indicated by `message_retention_duration`. :type message_retention_duration: :class:`datetime.timedelta` :param message_retention_duration: (Optional) Whether to retain acked messages. If set, acked messages are retained in the subscription's backlog for a duration indicated by `message_retention_duration`. If unset, defaults to 7 days. :rtype: dict :returns: ``Subscription`` resource returned from the API. """ path = '/%s' % (subscription_path,) resource = {'topic': topic_path} if ack_deadline is not None: resource['ackDeadlineSeconds'] = ack_deadline if push_endpoint is not None: resource['pushConfig'] = {'pushEndpoint': push_endpoint} if retain_acked_messages is not None: resource['retainAckedMessages'] = retain_acked_messages if message_retention_duration is not None: pb = _timedelta_to_duration_pb(message_retention_duration) resource['messageRetentionDuration'] = { 'seconds': pb.seconds, 'nanos': pb.nanos } return self.api_request(method='PUT', path=path, data=resource)