啥也不说了,先贴代码:defmonitor(client):run_heartbeat=client.run.heartbeatetc_rpc=client.etc.rpcdocument=etc_rpc.find_one({'server':'taskmanager'})rpc=document['host']+':'+document['port']ifprocess_ok('taskmanager'):run_heartbeat.update({'process':'taskmanager','rpc':rpc},{'$set':{'selftesttime':datetime.datetime.now().strftime('%Y-%m-%d%H:%M:%S'),'selftest':'ok'}})logging.info("update:selftestis'ok'")print"update:run_heartbeat.taskmanager.selftestis'ok'"else:run_heartbeat.update({'process':'taskmanager','rpc':rpc},{'$set':{'selftesttime':datetime.datetime.now().strftime('%Y-%m-%d%H:%M:%S'),'selftest':'processerror'}})logging.info("update:selftestis'processerror'")print"update:run_heartbeat.taskmanager.selftestis'processerror'"if__name__=="__main__":print"TaskMonitorbeginning......"sched=Scheduler()sched.daemonic=Falsesched.add_interval_job(monitor,seconds=int(tasktime),args=[client])sched.start()功能:每隔tasktime秒就运行一次monitor函数期望结果:在运行过程中通过CTRL+C停止求大神解决办法!
梦里花落0921
相关分类