Esempio n. 1
0
    def handleRequest(self):
        if not startup.IS_INIT_OK:
            print 'not init OK !!'
            try:
                self.finish()
            except:
                pass
            return
        request = None
        try:
            taskarg = ftsvr.getTaskRunArg()
            request = taskarg['data']
            heads = request.getAllHeaders()
            if not "log-type" in heads:
                return self._doHttpManager(request)

            _type = heads["log-type"]
            _group = heads["log-group"]
            body = request.content.read()

            pbody = self.parseBody(body, _type)

            if pbody:
                logid = ftsvr.doRedis(_group, "INCR", "global:logid:%s:%s" % (_group, _type))
                _date = time.strftime("%Y%m%d", time.localtime(int(time.time())))
                ftsvr.doRedis(_group, "HSETNX", "day1st:%s:%s" % (_group, _type), _date, logid)
                self.updateIndex(_type, _group, logid, pbody)
                self.sendToWriter(_type, _group, logid, body)
        except:
            ftlog.error()
        finally:
            try:
                request.finish()
            except:
                pass
Esempio n. 2
0
 def updateIndex(self, _type, _group, logid, pbody):
     type_conf = ftcon.getConf("freetime:log_type")
     if "index_field" in type_conf[_type]:
         need_index = type_conf[_type]["index_field"]
         timestamp = int(time.time())
         key = ""
         for i in need_index:
             key += str(pbody[i]) + '.'
         ftsvr.doRedis(_group, "RPUSH",
                       "index:%s:%s:%s" % (_group, _type, key[:-1]),
                       timestamp, logid)
Esempio n. 3
0
 def doSomeLogic(self):
     #for x in xrange(1):
     now = time.time()
     ftagent.query("GA01", "2222222222222:")
     spent = time.time() - now
     if spent > 0.1:
         ftlog.info("SPENT PPS...", spent)
     ftsvr.doRedis("user01", "SET", "zx", 1)
     for x in xrange(50000):
         x = x * 2
         x = x / 2
Esempio n. 4
0
 def updateIndex(self, _type, _group, logid, pbody):
     type_conf = ftcon.getConf("freetime:log_type")
     if "index_field" in type_conf[_type]:
         need_index = type_conf[_type]["index_field"]
         timestamp = int(time.time())
         key = ""
         for i in need_index:
             key += str(pbody[i]) + '.'
         ftsvr.doRedis(_group, "RPUSH",
                       "index:%s:%s:%s" % (_group, _type, key[:-1]),
                       timestamp, logid)
Esempio n. 5
0
    def doSomeLogic2(self):
        ftlog.info("MyProto do some logic in tasklet")
        #test redis aio
        ftsvr.doRedis("user01", "SET", "zx", 1)

        #Testing doHttp...
        #code, page = ftsvr.doHttp("GET", "http://www.google.com",
        #       {'User-Agent': ['Twisted']}) #test connect timeout
        #code, page = ftsvr.doHttp("GET", "http://news.sina.com.cn/",
        #       {'User-Agent': ['Twisted']}, '', 15, 0.1) #test request timeout
        #page = ftsvr.doHttp("GET", "http://news.sina.com.cn/sssss",
        #       {'User-Agent': ['Twisted']}) #test 404
        code, page = ftsvr.doHttp("POST", "http://127.0.0.1:8003/",
                                  {'User-Agent': ['Twisted']}, "HAHAHA")
        print code, page
        print "HTTP", code, len(page), page

        log_data = struct.pack("64s", "HAHAHA")
        ftlog.sendHttpLog("user01", "chip", log_data)

        #pipeline需要加锁,否则结果可能混乱,框架中已经加了lock,参见ftsvr代码
        count = 1000
        pipecount = 100
        st = time.time()
        for x in xrange(count / pipecount):
            if x % 100 == 0:
                ftlog.info(x)
            pl = ftsvr.getRedisPipe("user01")
            for y in xrange(pipecount):
                pl.set("zx", 1)
            result = ftsvr.doRedisPipe(pl)
            if len(result) != pipecount:
                ftlog.debug("ERRORPIPELINE")
        ftlog.info("SetPerS:", count / (time.time() - st))

        #test ftagent and udpquery
        ftlog.debug(ftcon.getConf("server"), caller=self)
        ftlog.debug(ftsvr.getTaskRunArg())
        ftlog.debug(ftsvr.doUdpQuery("LO01", "abcdefgh"))
        ftlog.debug(ftagent.query("GA01", "TCPTCPSENDBYAGENT"))

        #test cron
        _tstr = time.strftime('%Y%m%d', time.localtime())
        cron2 = FTCron(
            '{"times_in_day":{"first":"15:00","interval":5, "count":32},\
                        "days":{"first":"%s", "interval":"2m", "count":10}}' %
            (_tstr))
        ftlog.debug(cron2.getTimeList(), cron2.getDaysList())
        ftlog.debug("SEC=", cron2.getTodayNextLater())

        #test timer
        tr = FTTimer(3, self.timerFunc, 1, 2, 3, aaa=111)
Esempio n. 6
0
    def handleRequest(self):
        if not startup.IS_INIT_OK:
            print 'not init OK !!'
            try:
                self.finish()
            except:
                pass
            return
        request = None
        try:
            taskarg = ftsvr.getTaskRunArg()
            request = taskarg['data']
            heads = request.getAllHeaders()
            if not "log-type" in heads:
                return self._doHttpManager(request)

            _type = heads["log-type"]
            _group = heads["log-group"]
            body = request.content.read()

            pbody = self.parseBody(body, _type)

            if pbody:
                logid = ftsvr.doRedis(_group, "INCR",
                                      "global:logid:%s:%s" % (_group, _type))
                _date = time.strftime("%Y%m%d",
                                      time.localtime(int(time.time())))
                ftsvr.doRedis(_group, "HSETNX",
                              "day1st:%s:%s" % (_group, _type), _date, logid)
                self.updateIndex(_type, _group, logid, pbody)
                self.sendToWriter(_type, _group, logid, body)
        except:
            ftlog.error()
        finally:
            try:
                request.finish()
            except:
                pass
Esempio n. 7
0
 def mget(self):
     return ftsvr.doRedis("user01", "HMGET", "user:11111", "name",
                          "clientid")