コード例 #1
0
def run(property_dict) :
	pid = os.getpid()
	name = str(property_dict["key"])
	#设置log输出logid
	fastlog.set_logid(name + "_" + str(pid))
	#信号处理函数
	signal.signal(signal.SIGTERM, onsignal_term)
	#根据配置中定义的队列服务器地址和key,连接队列服务器
	get_queue_data = getqueuedata.GetQueuData(property_dict["servers"], str(property_dict["key"]))

	##my data prepare
	##------------------------START-----------------------------------
	#configure message
	cf = ConfigParser.ConfigParser()
	cf.readfp(open('./conf/rinMethod.ini','r'))
	c = configData.configData(cf)
	#data parser
	parser = stdSampleParser.stdSampleParser()
	#init timeManager data
	t = timeManager.timeManager(int(c.longTimePeriod),int(c.shortTimePeriod))
	now = time.time()
	t.setEndPoint(int(now))
	effectMonitorInstance = effectMonitor.effectMonitor(c,t)
	##------------------------END-----------------------------------

	#循环从队列中获取数据
	get_null_count = 0
	while  True :
		#如果接收到kill信号,则会做如下退出处理
		if break_flag :
			print "break while loop in " + name
			fastlog.info("break while loop in " + name)
			##------------------------START-----------------------------------
			##结束进程前的后续操作
			##------------------------END-------------------------------------
			break
		try :
			#从连接上的队列集群中,随机一台服务器中获取一条数据
			#------------------------START-----------------------------------
			(data, server_addr) = get_queue_data.randomgetonedata()
			if data == None or data == "" :
				get_null_count += 1
				if get_null_count >= 10 :
					get_null_count = 0
					time.sleep(0.05)
				continue
			#fastlog.info("server: " + server_addr + " data: " + data)
			get_null_count = 0
			#------------------------END-------------------------------------

			#------------------------START-----------------------------------
			#print data
			effectMonitorInstance.deal(parser.parse(data))
			effectMonitorInstance.printStatsItemMsgToLog()
			parser.clear()
			#------------------------END-------------------------------------
		except Exception, e:
			fastlog.error("parser data Exception: " + str(e) + " data: " + str(data))
コード例 #2
0
def run(property_dict) :
    pid = os.getpid()
    name = str(property_dict["key"])
    #设置log输出logid
    fastlog.set_logid(name + "_" + str(pid))

    #信号处理函数
    signal.signal(signal.SIGTERM, onsignal_term)
    #根据配置中定义的队列服务器地址和key,连接队列服务器
    get_queue_data = getqueuedata.GetQueuData(property_dict["servers"], str(property_dict["key"]))

    #------------------------START-----------------------------------
    #如果需要将队列中获取的内容落地,则需要加上这段代码
    #------------------------END-------------------------------------

    #循环从队列中获取数据
    get_null_count = 0
    while  True :
        #如果接收到kill信号,则会做如下退出处理
        #recv kill signal the break loop
        if break_flag :
            print "break while loop in " + name
            fastlog.info("break while loop in " + name)
            ##------------------------START-----------------------------------
            ##结束进程前的后续操作
            ##------------------------END-------------------------------------
            break
        try :
            #从连接上的队列集群中,随机一台服务器中获取一条数据
            (result_data, server_addr) = get_queue_data.randomgetonedata()
            if result_data == None or result_data == "" :
                get_null_count += 1
                if get_null_count >= 10 :
                    get_null_count = 0
                    time.sleep(0.05)
                continue
            #fastlog.info("server: " + server_addr + " data: " + result_data)
            get_null_count = 0

            ## parser action data
            #------------------------START-----------------------------------
            #二次开发者根据需求解析这一条数据
            print "server: " + server_addr + " data: " + result_data
            sys.stdout.flush()

            #------------------------END-------------------------------------

        except Exception, e:
            fastlog.error("parser data Exception: " + str(e) + " data: " + str(result_data))
コード例 #3
0
def onsignal_term(a,b):
    global break_flag
    print str(__file__) + "  " + str(os.getpid()) + " process recv signal"
    fastlog.info(str(__file__) + "  " + str(os.getpid()) + " process recv signal")
    break_flag = True