Przeglądaj źródła

将日志 与 机器人状态详情进行缓存,

hl 3 tygodni temu
rodzic
commit
6ffa98985c
1 zmienionych plików z 10 dodań i 3 usunięć
  1. 10 3
      src/Interval.js

+ 10 - 3
src/Interval.js

@@ -104,8 +104,12 @@ function cacheLogs() {
             let port = value.port
             let port = value.port
             let n = 200
             let n = 200
             let messlist = value.messlist
             let messlist = value.messlist
-            if (value.id !== -1 && port !== -1) {
-                logger.info(`~~~缓存日志${value.id}`)
+            if (value.id !== -1 && port !== -1 && value.threadStatus === robot.RobotStatus.RUNNING) {
+                // 将数组转换为 JSON 字符串
+                const jsonString = JSON.stringify(messlist);
+                const byteSize = Buffer.byteLength(jsonString, 'utf8');
+                const megabyteSize = byteSize / (1024 * 1024);
+                logger.info(`~~~缓存日志${value.id}--占用大小:${megabyteSize} M`)
                 try {
                 try {
                     var logPath = "./logs" + port
                     var logPath = "./logs" + port
                     logger.info(`访问-日志相对目录:${logPath}`)
                     logger.info(`访问-日志相对目录:${logPath}`)
@@ -145,7 +149,10 @@ function cachePredictorState() {
             let port = value.port
             let port = value.port
             let predictorState = value.predictorState
             let predictorState = value.predictorState
             if (value.id !== -1 && port !== -1 && value.threadStatus === robot.RobotStatus.RUNNING) {
             if (value.id !== -1 && port !== -1 && value.threadStatus === robot.RobotStatus.RUNNING) {
-                logger.info(`~~~缓存机器人状态详情${value.id}`)
+                const jsonString = JSON.stringify(messlist);
+                const byteSize = Buffer.byteLength(jsonString, 'utf8');
+                const megabyteSize = byteSize / (1024 * 1024);
+                logger.info(`~~~缓存机器人状态详情${value.id}--占用大小:${megabyteSize} M`)
                 var accUrl = "http://127.0.0.1:" + port
                 var accUrl = "http://127.0.0.1:" + port
                 http.request_get(`${accUrl}/predictor_state`, {...config.headers})
                 http.request_get(`${accUrl}/predictor_state`, {...config.headers})
                     .then((data) => {
                     .then((data) => {