示例#1
0
    def __init__(self,
                 id_generator=None,
                 data_converter=lambda x: x,
                 operation=BucketOperators.UPSERT):
        # type: (IdGenerator, DataConverter, BucketOperator) -> None
        """
        Initialise ingester.

        :param DataConverter data_converter: Single parameter Callable which takes a JSON
            input and returns a transformed JSON output.
        :param IdGenerator id_generator: Callable that takes a JSON input and
            returns an ID string
        :param BucketOperator operation: Callable that takes a bucket object, a key and a
            value and applies the key and value to the bucket (e.g. upsert/insert/replace)
        """
        if not isinstance(operation, BucketOperator):
            raise ArgumentError("Operation is not a BucketOperator")

        if operation == BucketOperators.REPLACE and not id_generator:
            raise ArgumentError("Replace cannot use default ID generator.")

        self.id_generator = id_generator or (lambda x: str(uuid.uuid4()))
        self.data_converter = data_converter
        self.operation = operation
    def _design_poll(self, name, mode, oldres, timeout=5, use_devmode=False):
        """
        Poll for an 'async' action to be complete.
        :param string name: The name of the design document
        :param string mode: One of ``add`` or ``del`` to indicate whether
            we should check for addition or deletion of the document
        :param oldres: The old result from the document's previous state, if
            any
        :param float timeout: How long to poll for. If this is 0 then this
            function returns immediately
        :type oldres: :class:`~couchbase_core.result.HttpResult`
        """
        if not timeout:
            return True

        if timeout < 0:
            raise ArgumentError.pyexc("Interval must not be negative")

        t_end = time.time() + timeout
        old_rev = None

        if oldres:
            old_rev = self._doc_rev(oldres)

        while time.time() < t_end:
            try:
                cur_resp = self.design_get(name, use_devmode=use_devmode)
                if old_rev and self._doc_rev(cur_resp) == old_rev:
                    continue

                try:
                    if not self._poll_vq_single(
                            name, use_devmode, cur_resp.value):
                        continue
                    return True

                except CouchbaseError:
                    continue

            except CouchbaseError:
                if mode == 'del':
                    # Deleted, whopee!
                    return True

        raise exceptions.TimeoutError.pyexc(
            "Wait time for design action completion exceeded")
示例#3
0
    def query(self, *args, **kwargs):
        """
        Reimplemented from base class.

        This method does not add additional functionality of the
        base class' :meth:`~couchbase_v2.bucket.Bucket.query` method (all the
        functionality is encapsulated in the view class anyway). However it
        does require one additional keyword argument

        :param class itercls: A class used for instantiating the view
          object. This should be a subclass of
          :class:`~couchbase_v2.asynchronous.view.AsyncViewBase`.
        """
        if not issubclass(kwargs.get('itercls', None), AsyncViewBase):
            raise ArgumentError.pyexc("itercls must be defined "
                                      "and must be derived from AsyncViewBase")

        return super(AsyncBucket, self).query(*args, **kwargs)