| 
					
				 | 
			
			
				@@ -35,6 +35,7 @@ function getAppMap() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 function getApp(key) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     let app = { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         id: -1, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        port: -1, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         childProcess: undefined, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         nowBalance: 0, 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         messlist: [], 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -73,10 +74,10 @@ async function run(param) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         app.status = 1 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				- 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         // 初始化机器人状态 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         app.threadStatus = RobotStatus.START_PENDING 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         app.id = key 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        app.port = param.callPort 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         robotStatus(app) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         /**** 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -89,11 +90,15 @@ async function run(param) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         // let configName = "config.toml";        //配置文件 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         let configName = "config.json";        //配置文件 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         let appPath = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        if (platform === 'win32') {//直接运行相对路径 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            appPath = config.winPath + "/" + app.id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } else {//打包为docker 镜像 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            appPath = config.linuxPath + "/" + app.id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //相对路径存放 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        appPath = config.filePath + "/" + app.id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //1. 检查目录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        file.checkPathSync(appPath); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // if (platform === 'win32') {//直接运行相对路径 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //     appPath = config.winPath + "/" + app.id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // } else {//打包为docker 镜像 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        //     appPath = config.linuxPath + "/" + app.id 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        // } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         /**** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				          *** 第三步:rust 启动程序检查(下载更新) 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -102,8 +107,6 @@ async function run(param) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         var isDow = false 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         var scheduleDow = 0 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         var scheduleConfig = 0 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        //1. 检查目录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        file.checkPathSync(appPath); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         //2、 检查执行程序 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         var destination = appPath + "/" + exeName 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         if (!file.checkFilePath(destination)) { 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -232,7 +235,7 @@ async function run(param) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         const configPath = appPath + "/" + configName 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         logger.info(`文件地址:${exePath}-----${configPath}`); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         const command = exePath 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        const args = ['--config=' + configPath] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        const args = ['--config=' + configPath, '--port=' + app.port] 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         app.childProcess = spawn(command, args) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -453,7 +456,7 @@ async function closeAppAll() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                         logger.error(`进程${pid} 杀死失败: ${error}`); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     logger.info(`进程${pid} 杀死成功`); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    logger.info(`当前app:`, app); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    // logger.info(`当前app:`, app); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     app.threadStatus = RobotStatus.STOP_PENDING 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                     robotStatus(app) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 }); 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -465,16 +468,16 @@ async function closeAppAll() { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             await delay(1000) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             var str = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             appMap.forEach((value, key) => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                str += "机器人:"+key+",当前状态:"+value.threadStatus+"\t" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                if(value.threadStatus !== RobotStatus.STOPPED){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-                    z+=1 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                str += "机器人:" + key + ",当前状态:" + value.threadStatus + "\t" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                if (value.threadStatus !== RobotStatus.STOPPED) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+                    z += 1 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             }); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             logger.info(str) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            if(z===0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            if (z === 0) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 logger.info(`策略全部关闭~~开始关闭node`); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 break 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-            }else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 logger.info(`等待关闭~~策略!`); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         } 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -535,10 +538,11 @@ function robotStatus(app) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 // 上报-余额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 function robotAmount(app) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    var accUrl = "http://127.0.0.1:" + app.port 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     //拿到策略余额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				         var config = getRustConfig() 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-        http.request_get(`${config.rustUrl}/account`, {...config.headers}) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        http.request_get(`${accUrl}/account`, {...config.headers}) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				             .then((data) => { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 var d = JSON.parse(data) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                 //余额有变动上报一次 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -574,5 +578,5 @@ function delRobot(app) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 module.exports = { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-    run, closeApp, restartApp, delRobot, robotStatus, robotAmount, closeAppAll, appMap, getAppMap, RobotStatus 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+    run, closeApp, restartApp, delRobot, robotStatus, robotAmount, closeAppAll, appMap, getApp, getAppMap, RobotStatus 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 }; 
			 |