示例#1
0
    def _sub_unsub_in_groups(self, tags, method, with_future=True):
        if isinstance(tags, str):
            tags = set([tags])

        if not isinstance(tags, set):
            tags = set(tags)

        def fix_result(f):
            return f if with_future else None

        if not tags:
            return fix_result(READY_ACK_FUTURE)

        if len(tags) < self.MESSAGE_MAX_ITEM_COUNT:
            return fix_result(method(tags))

        futures = [
            method(set(tags_group))
                for tags_group in split_in_groups(tags, self.MESSAGE_MAX_ITEM_COUNT)
        ]

        if not with_future:
            return

        return CheckAllFuturesSucceed(futures)
示例#2
0
    def _reconstruct_outgoing(self):
        with self._lock:
            resend_ids = [id for id, task in self._running.iteritems() if task.is_resend]

            for id in resend_ids:
                self._running.pop(id)

            self._outgoing = deque(
                self._running[id]
                    for id in sorted(self._running.keys())
            )

            # XXX _subscriptions после _outgoing, чтобы не приходили события по
            # тем тегам, на которые пользователь Client не подписан (ну, типа
            # инвариант)

            # XXX For now subscribes for already subscribed tags will not be
            # trigger events in journal

            # FIXME Global split feature in all _push callers?

            for tags in split_in_groups(self._subscriptions, self.MESSAGE_MAX_ITEM_COUNT):
                self._do_push(
                    self._create_subscribe_message(tags),
                    self.__FAKE_PROMISE,
                    is_resend=True
                )
示例#3
0
文件: storages.py 项目: cgorbit/rem
    def convert_in_memory_tags_to_cloud_if_need(self):
        if not self._has_cloud_setup():
            return False

        updates = []

        for tag_name, tag in self.inmem_items.iteritems():
            must_be_cloud = self._is_cloud_tag_name(tag_name) \
                and not tag.IsRemote() # Hack for disable_remote_tags

            if must_be_cloud == tag.IsCloud():
                continue

            elif must_be_cloud:
                if tag.IsLocallySet():
                    updates.append((tag_name, ETagEvent.Set))

                self._make_tag_cloud(tag)
            else:
                logging.error("Tag %s is cloud, but must not be" % tag_name)

        if not updates:
            return False

        logging.info("before conversion %d tags to CloudTag's" % len(updates))

        cloud = self._create_cloud_client(lambda ev: None)

        try:
            for bucket in split_in_groups(updates, 100000): # TODO Fix cloud_client.update
                cloud.update(bucket).get()
        finally:
            try:
                cloud.stop()
            except:
                logging.exception("Failed to stop temporary cloud client")

        logging.info("after conversion %d tags to CloudTag's" % len(updates))

        return True