Ver Fonte

as 调整

hl há 8 meses atrás
pai
commit
c05719faf5
2 ficheiros alterados com 41 adições e 8 exclusões
  1. 26 6
      src/Interval.js
  2. 15 2
      src/robot.js

+ 26 - 6
src/Interval.js

@@ -1,6 +1,7 @@
 const robot = require('./robot')
 const web = require('./web')
 const {logger} = require("./utils/logger");
+const {tr} = require("date-fns/locale");
 
 
 /*******
@@ -9,7 +10,7 @@ const {logger} = require("./utils/logger");
 function init() {
     // reportNodeStatus()
     reportDel()
-    // reportStatus()
+    reportSearchPositions()
     reportAmount()
     logger.info('--定时任务 启动');
 }
@@ -38,14 +39,33 @@ function reportDel() {
 }
 
 
-// 5秒扫描本机所有机器人状态,进行上报
-function reportStatus() {
+// 定时扫描,如果发现机器人关闭或者错误,并且停止时间超过1分钟以上了,就进行清仓检查
+function reportSearchPositions() {//DOTO node 代码修改完毕,待测试
     const intervalInMilliseconds = 3000;
     setInterval(() => {
+        logger.info('--当前 定时检查清仓');
         robot.appMap.forEach((value, key) => {
-            // logger.info('当前',robot.appMap);
-            if (value.id !== -1 && value.threadStatus !== robot.RobotStatus.STOPPED) {
-                robot.robotStatus(value)
+
+            let isStartTime = value.closeTime + (1000*60)
+            if (value.id !== -1 && isStartTime >= new Date().getTime() &&  (value.threadStatus === robot.RobotStatus.STOPPED || value.threadStatus === robot.RobotStatus.ERROR)
+                // && value.isClearance === false
+            ) {
+                logger.info('发起清仓检查:'+value.id+"停机时间:"+value.closeTime +"当前时间:"+new Date().getTime());
+                // robot.robotStatus(value)
+                // {"id":"375",
+                // "callPort":"1111",
+                // "path":"80654e330ed67df2880231a67925e984as-rust",
+                // "programName":"v3.3.2_clear",
+                // "strategyName":"as","checkId":"467"}
+
+                robot.searchPositions({
+                    "id":value.id,
+                    "callPort":value.port,
+                    "path":value.path,
+                    "programName":value.programName,
+                    "strategyName":value.strategyName,
+                })
+                // value.isClearance = true
             }
         });
     }, intervalInMilliseconds);

+ 15 - 2
src/robot.js

@@ -36,6 +36,9 @@ function getApp(key) {
     let app = {
         id: -1,
         port: -1,
+        path:"",
+        programName:"",
+        strategyName:"",
         childProcess: undefined,
         nowBalance: -1,
         messlist: [],
@@ -44,6 +47,8 @@ function getApp(key) {
         threadStartTime: -1,
         status: 0,
         restartStatus: 0,
+        closeTime:0,
+        isClearance:false,
 
     }
     // logger.info(appMap, appMap.has(key));
@@ -81,6 +86,10 @@ async function run(param) {
         app.threadStatus = RobotStatus.START_PENDING
         app.id = key
         app.port = param.callPort
+        app.path = param.path
+        app.programName = param.programName
+        app.strategyName = param.strategyName
+        app.isClearance = false
         robotStatus(app)
 
         /****
@@ -259,6 +268,7 @@ async function run(param) {
             robotStatus(app)
             app.childProcess = undefined
             app.status = 0
+            app.closeTime = new Date().getTime()
         });
         app.childProcess.on('exit', (code, signal) => {
             logger.info(`子进程退出-exit,退出码: ${code}, 信号: ${signal}`);
@@ -266,6 +276,7 @@ async function run(param) {
             robotStatus(app)
             app.childProcess = undefined
             app.status = 0
+            app.closeTime = new Date().getTime()
         });
 
         app.childProcess.on('close', (code) => {
@@ -274,6 +285,7 @@ async function run(param) {
             robotStatus(app)
             app.childProcess = undefined
             app.status = 0
+            app.closeTime = new Date().getTime()
         });
         app.threadStatus = RobotStatus.RUNNING
         robotStatus(app)
@@ -301,6 +313,7 @@ async function closeApp(param) {
                 logger.info(`进程${pid} 杀死成功`);
                 logger.info(`当前app:`, app);
                 app.threadStatus = RobotStatus.STOP_PENDING
+                app.isClearance = false
                 robotStatus(app)
             });
         }
@@ -343,7 +356,7 @@ async function searchPositions(param) {
         // {"id":"375","callPort":"1111","path":"80654e330ed67df2880231a67925e984as-rust","programName":"v3.3.2_clear","strategyName":"as","checkId":"467"}
         var key = param.id
         var appName = param.path
-        var checkId = param.checkId
+        var r_id = param.id
         let newAppName = "4l_as_" + appName;
         let configName = "config.json";        //配置文件
         var programName = param.programName
@@ -362,7 +375,7 @@ async function searchPositions(param) {
         const asName = appPath + "/" + newAppName
         const configPath = appPath + "/" + configName
         const appPort = param.callPort
-        const command = `sudo ${asName} --config=${configPath} --port=${appPort} --run_mode=1 --check_id=${checkId}`
+        const command = `sudo ${asName} --config=${configPath} --port=${appPort} --run_mode=1 --r_id=${r_id}`
 
         exec(command, (error, stdout, stderr) => {
             if (error) {