コード例 #1
0
ファイル: invalidation.py プロジェクト: yzou/openlibrary
    def reload(self):
        """Triggers on_new_version event for all the documents modified since last_poll_time.
        """
        t = datetime.datetime.utcnow()
        reloaded = False

        keys = []
        for prefix in self.prefixes:
            q = {
                "key~": prefix + "*",
                "last_modified>": self.last_poll_time.isoformat(),
                "limit": 1000
            }
            keys += web.ctx.site.things(q)

        if keys:
            web.ctx._invalidation_inprogress = True
            docs = web.ctx.site.get_many(keys)
            for doc in docs:
                try:
                    client._run_hooks("on_new_version", doc)
                except Exception:
                    pass
            self.last_update_time = max(doc.last_modified for doc in docs)
            reloaded = True
            del web.ctx._invalidation_inprogress

        self.last_poll_time = t
        return reloaded
コード例 #2
0
    def reload(self):
        """Triggers on_new_version event for all the documents modified since last_poll_time.
        """
        t = datetime.datetime.utcnow()
        reloaded = False

        keys = []
        for prefix in self.prefixes:
            q = {"key~": prefix + "*", "last_modified>": self.last_poll_time.isoformat(), "limit": 1000}
            keys += web.ctx.site.things(q)

        if keys:
            web.ctx._invalidation_inprogress = True
            docs = web.ctx.site.get_many(keys)
            for doc in docs:
                try:
                    client._run_hooks("on_new_version", doc)
                except Exception:
                    pass
            self.last_update_time = max(doc.last_modified for doc in docs)
            reloaded = True
            del web.ctx._invalidation_inprogress

        self.last_poll_time = t
        return reloaded
コード例 #3
0
ファイル: code.py プロジェクト: candeira/openlibrary
    def POST(self):
        global local_ip
        if local_ip is None:
            local_ip = socket.gethostbyname(socket.gethostname())

        if web.ctx.ip != "127.0.0.1" and web.ctx.ip.rsplit(".", 1)[0] != local_ip.rsplit(".", 1)[0]:
            raise Forbidden("Allowed only in the local network.")

        data = simplejson.loads(web.data())
        if not isinstance(data, list):
            data = [data]
        for d in data:
            thing = client.Thing(web.ctx.site, d['key'], client.storify(d))
            client._run_hooks('on_new_version', thing)
コード例 #4
0
    def POST(self):
        global local_ip
        if local_ip is None:
            local_ip = socket.gethostbyname(socket.gethostname())

        if web.ctx.ip != '127.0.0.1' and web.ctx.ip.rsplit('.', 1)[0] != local_ip.rsplit('.', 1)[0]:
            raise Forbidden('Allowed only in the local network.')

        data = json.loads(web.data())
        if not isinstance(data, list):
            data = [data]
        for d in data:
            thing = client.Thing(web.ctx.site, d['key'], client.storify(d))
            client._run_hooks('on_new_version', thing)
        return delegate.RawText('ok')