Exemplo n.º 1
0
    def _set_result_from_operation(self):
        """Set the result or exception from the operation if it is complete."""
        # This must be done in a lock to prevent the polling thread
        # and main thread from both executing the completion logic
        # at the same time.
        with self._completion_lock:
            # If the operation isn't complete or if the result has already been
            # set, do not call set_result/set_exception again.
            # Note: self._result_set is set to True in set_result and
            # set_exception, in case those methods are invoked directly.
            if not self._operation.done or self._result_set:
                return

            if self._operation.HasField('response'):
                response = _helpers._from_any_pb(
                    self._result_type, self._operation.response)
                self.set_result(response)
            elif self._operation.HasField('error'):
                exception = exceptions.GoogleCloudError(
                    self._operation.error.message,
                    errors=(self._operation.error))
                self.set_exception(exception)
            else:
                exception = exceptions.GoogleCloudError(
                    'Unexpected state: Long-running operation had neither '
                    'response nor error set.')
                self.set_exception(exception)
Exemplo n.º 2
0
    def metadata(self):
        """google.protobuf.Message: the current operation metadata."""
        if not self._operation.HasField('metadata'):
            return None

        return _helpers._from_any_pb(
            self._metadata_type, self._operation.metadata)
Exemplo n.º 3
0
    def _call_fut(self, pb_type, any_pb):
        from google.cloud._helpers import _from_any_pb

        return _from_any_pb(pb_type, any_pb)
    def _call_fut(self, pb_type, any_pb):
        from google.cloud._helpers import _from_any_pb

        return _from_any_pb(pb_type, any_pb)