Selaa lähdekoodia

新增-新策略对应 获取机器人状态接口

hl 5 kuukautta sitten
vanhempi
commit
cf9821c391
1 muutettua tiedostoa jossa 31 lisäystä ja 19 poistoa
  1. 31 19
      src/robot.js

+ 31 - 19
src/robot.js

@@ -557,27 +557,39 @@ function delRobot(app) {
 function predictorState(port) {
     logger.info('#####################predictorState:');
     var accUrl = "http://127.0.0.1:" + port
-    //拿到策略余额
-    try {
-        var config = getRustConfig()
-        var rul = `${accUrl}/predictor_state`
-        logger.info('#####################-rul', rul);
-        http.request_get(rul, {...config.headers})
-            .then((data) => {
-                logger.info('#####################-d', data);
-                return {'code': 200, 'data': data, "message": "SUCCESS"}
-            }).catch((error) => {
-            // 处理可能发生的错误
+    var config = getRustConfig()
+
+    // curl -X GET -H "auth: 4L" -H "token: r7T\$8gBV\!f&L@E2+" "http://127.0.0.1:111/predictor_state"
+    exec(`sudo curl -X GET -H "auth: ${config.headers.auth}" -H "token: ${config.headers.token}" "http://127.0.0.1:${port}/predictor_state"`, (error, stdout, stderr) => {
+        if (error) {
             logger.info(`#####################汇报:获取状态请求失败: ${error.message}`)
-            // logger.error(`#####################汇报:获取状态请求失败: ${error.message}`)
-            return {'code': -1, 'data': null, "message": `获取状态请求失败${error.message}`}
-        });
-    } catch (e) {
-        // logger.error('请求失败!:', e)
-        logger.info('请求失败!:', e)
-        return {'code': -1, 'data': null, "message": "获取状态请求出错"}
-    }
+            return {'code': -1, 'data': null, "message": `获取状态请求失败`}
+        }
 
+        logger.info('#####################-d', stdout);
+        return {'code': 200, 'data': stdout, "message": "SUCCESS"}
+    });
+
+    // //拿到策略余额
+    // try {
+    //     var config = getRustConfig()
+    //     var rul = `${accUrl}/predictor_state`
+    //     logger.info('#####################-rul', rul);
+    //     http.request_get(rul, {...config.headers})
+    //         .then((data) => {
+    //             logger.info('#####################-d', data);
+    //             return {'code': 200, 'data': data, "message": "SUCCESS"}
+    //         }).catch((error) => {
+    //         // 处理可能发生的错误
+    //         logger.info(`#####################汇报:获取状态请求失败: ${error.message}`)
+    //         // logger.error(`#####################汇报:获取状态请求失败: ${error.message}`)
+    //         return {'code': -1, 'data': null, "message": `获取状态请求失败${error.message}`}
+    //     });
+    // } catch (e) {
+    //     // logger.error('请求失败!:', e)
+    //     logger.info('请求失败!:', e)
+    //     return {'code': -1, 'data': null, "message": "获取状态请求出错"}
+    // }
 }
 
 module.exports = {