sinfo = worker.register(discover_config.TERMINAL_SRV_D, http_listen_port, 0, None) worker.work() except Exception, e: print "worker register errxor exception:", e logger.exception(e) exit(0) redis_mgr = RedisMgr(redis_conf.startup_nodes) redis_queue_sender = RedisQueueSender(redis_mgr) handler = terminal_handler.TerminalHandler( conn_mgr, debug, imei_timer_mgr, op_log_dao=OPLogDAO.new(mongo_client, thread_pool), broadcastor=broadcastor, pet_dao=PetDAO.new(mongo_client, thread_pool), new_device_dao=NewDeviceDAO.new(mongo_client, thread_pool), msg_rpc=msg_rpc, redis_queue_sender=redis_queue_sender, server_id=sinfo.id, unreply_msg_mgr=unreply_msg_mgr, ) conn_mgr.CreateTcpServer("", listen_port, handler) webapp = Application( [ (r"/op_log", http_handlers.GetOpLogHandler), (r"/unicast", http_handlers.UnicastHandler), #(r"/send_command", http_handlers.SendCommandHandler), #(r"/send_command2", http_handlers.SendCommandHandler2),
broadcastor = broadcast.BroadCastor(conn_mgr) imei_timer_mgr = imei_timer.ImeiTimer() unreply_msg_mgr = unreply_msg2.UnreplyMsgMgr2() # no_heart_msg_mgr = noheart_msg.NoHeartMsgMgr() IOLoop.current().run_sync(_async_init) msg_rpc = MsgRPC(SysConfig.current().get(sys_config.SC_MSG_RPC_URL)) term_rpc = terminal_rpc.TerminalRPC(SysConfig.current().get( sys_config.SC_TERMINAL_RPC_URL)) handler = terminal_handler.TerminalHandler( conn_mgr, debug, imei_timer_mgr, op_log_dao=OPLogDAO.new(mongo_meta=mongo_conf.op_log_mongo_meta), broadcastor=broadcastor, pet_dao=PetDAO.new(mongo_meta=mongo_conf.op_log_mongo_meta), user_dao=UserDAO.new(mongo_meta=mongo_conf.op_log_mongo_meta), new_device_dao=NewDeviceDAO.new( mongo_meta=mongo_conf.op_log_mongo_meta), msg_rpc=msg_rpc, device_setting_mgr=device_setting_mgr.DeviceSettingMgr( NewDeviceDAO.new(mongo_meta=mongo_conf.op_log_mongo_meta)), unreply_msg_mgr=unreply_msg_mgr, # no_heart_msg_mgr=no_heart_msg_mgr terminal_rpc=term_rpc) conn_mgr.CreateTcpServer("", listen_port, handler) webapp = Application( [(r"/op_log", http_handlers.GetOpLogHandler), (r"/send_command", http_handlers.SendCommandHandler), (r"/send_command2", http_handlers.SendCommandHandler2),
(r"/device/remove_device_info", handlers.RemoveDeviceInfo), (r"/device/set_sim_info", handlers.SetSimInfo), #(r"/device/switch_light", handlers.SwitchLight), # (r"/device/get_light_status", handlers.GetDeviceSwitchLightStatus), (r"/device/send_get_wifi_list_cmd", handlers.SendGetWifiListCmd), (r"/device/get_wifi_list", handlers.GetWifiList), #(r"/device/reboot_device_cmd", handlers.RebootDeviceCmd), (r"/device/get_device_status", handlers.GetPetStatusInfo), (r"/app/get_config", handlers.AppConfig), ], autoreload=True, debug=True, user_dao=UserDAO.new(mongo_meta=mongo_conf.user_mongo_meta), global_dao=GlobalDAO.new(mongo_meta=mongo_conf.global_mongo_meta), auth_dao=AuthDAO.new(mongo_meta=mongo_conf.auth_mongo_meta), pet_dao=PetDAO.new(mongo_meta=mongo_conf.pet_mongo_meta), device_dao=NewDeviceDAO.new(mongo_meta=mongo_conf.pet_mongo_meta), appconfig=conf, ) class _UserSrvConsole(Console): def handle_cmd(self, stream, address, cmd): if len(cmd) == 1 and cmd[0] == "quit": self.send_response(stream, "Byte!") return False elif len(cmd) == 0: pass elif len(cmd) == 1 and cmd[0] == "reload-config": newconf = loadJsonConfig() webapp.settings["appconfig"] = newconf
def testfun(uid): conf = loadJsonConfig("../configs/config.json") mongo_conf = MongoConfig2(conf["mongodb"]) pet_dao = PetDAO.new(mongo_meta=mongo_conf.pet_mongo_meta) count = yield pet_dao.get_pet_count(uid) print "count:", count