예제 #1
0
    def _dispatch_packet(self, head=Protocol.NET_HEAD(), packet_data=""):
        header = packet_data
        url = Protocol.get_url(header)
        if not url:
            return
        params = Protocol.urlparams2dict(url)
        try:
            service = url[0:8]
            if service != "/chelun?":
                #logger.error("Recv|not chelun service:%s|header:%s",url,header)
                return
            query = params["query"]
            cityid = params["cityid"]
            if not query:
                logger.error("Recv|invalid query:%s", url)
                return

            citykey = DataSource.get_weather_citykey(cityid)
            if not citykey:
                logger.error("Recv|invalid cityid:%s", url)
                return

#logger.debug("Recv|Url:%s",url)
            task = Protocol.REQUEST_PACKET()
            task.request_type = head.request_type
            task.request_key = citykey
            task.request_tick = Utils.gettickcount()

            if query in ["weather", "weather2"]:
                weather_data = KvCache.get_data_from_cache(k=citykey)
                if not weather_data:
                    logger.debug(
                        "Recv|get_data_from_cache failed;then ask worker;%s",
                        url)
                    MsgPipe.MsgPipe.push(fileno=self.client_socket.fileno(),
                                         sessionid=self.client_session_id,
                                         msgdata=task)
                    return
                logger.debug("Recv|get_data_from_cache succ;%s", url)
                self.send_data_bychunked(weather_data)
                return
            elif query == "weather3":
                task.request_type = "TEST"
                logger.debug("Recv|Test;%s", url)
                MsgPipe.MsgPipe.push(fileno=self.client_socket.fileno(),
                                     sessionid=self.client_session_id,
                                     msgdata=task)
                return
            pass

        except:
            pass
        pass
예제 #2
0
    def onProcessTimerTask(self):
        now = Utils.gettimesamp()
        if now > self._last_update_time + 1800:
            willupdatekeys = KvCache.get_willupdatekeys_from_cache()
            self._last_update_time = now
            for k in willupdatekeys:
                task = Protocol.REQUEST_PACKET()
                task.request_type = "JOB"
                task.request_key = k
                task.request_tick = Utils.gettickcount()
                MsgPipe.MsgPipe.push(fileno=0, sessionid=0, msgdata=task)

        if now > self._last_flush_time + 60:
            self._last_flush_time = now
            KvCache.flush_cache()