|
@@ -1,10 +1,10 @@
|
|
|
const file = require("./utils/file");
|
|
|
const {getRustConfig} = require("./config");
|
|
|
-const {spawn, exec, fork, execSync} = require("child_process");
|
|
|
+const {spawn, exec, execSync} = require("child_process");
|
|
|
const {logger} = require("./utils/logger");
|
|
|
const http = require("./utils/http");
|
|
|
-const e = require("express");
|
|
|
-const {is, tr} = require("date-fns/locale");
|
|
|
+// const e = require("express");
|
|
|
+// const {is, tr} = require("date-fns/locale");
|
|
|
/*******
|
|
|
* web
|
|
|
* **** */
|
|
@@ -106,7 +106,22 @@ async function run(param) {
|
|
|
//相对路径存放
|
|
|
appPath = config.filePath + "/" + app.id + "/" + strategyName + "/" + programName
|
|
|
//1. 检查目录
|
|
|
- file.checkPathSync(appPath);
|
|
|
+ let is_exist = file.checkFilePath(appPath)
|
|
|
+ // 目录不存在即是新策略,创建前清理机器人下不用的策略包
|
|
|
+ if (!is_exist){
|
|
|
+ // 清理该机器人下历史的策略包 sudo find ~/4l_capital_central_control_client/rust/203 -mindepth 1 -delete
|
|
|
+ let clear_command = `sudo find ` + config.filePath + "/" + app.id + ` -mindepth 1 -delete`
|
|
|
+ exec(clear_command, (error, stdout, stderr) => {
|
|
|
+ if (error) {
|
|
|
+ logger.error(`清理不用的策略文件:清理失败: ${error}`);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // 时间给到文件清理
|
|
|
+ await delay(1000);
|
|
|
+ // 同步创建目录
|
|
|
+ file.mkdir(appPath);
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/****
|
|
|
*** 第三步:rust 启动程序检查(下载更新)
|
|
@@ -117,11 +132,14 @@ async function run(param) {
|
|
|
var scheduleConfig = 0
|
|
|
//2、 检查执行程序
|
|
|
var destination = appPath + "/" + exeName
|
|
|
- if (!file.checkFilePath(destination)) {
|
|
|
+ // 确认路径是否存在
|
|
|
+ let is_program_exist = file.checkFilePath(destination);
|
|
|
+ if (!is_program_exist) {
|
|
|
app.threadStatus = RobotStatus.DOWNLOADING
|
|
|
robotStatus(app)
|
|
|
isDow = true
|
|
|
var dowHeaders = {...config.headers};
|
|
|
+
|
|
|
if (platform === 'win32') {
|
|
|
downloadFileWithPowerShell(
|
|
|
config.baseUrl + config.dowAppURL + '/?path=' + appName,
|
|
@@ -248,7 +266,7 @@ async function run(param) {
|
|
|
//3. spawn启动
|
|
|
const exePath = appPath + "/" + exeName
|
|
|
const configPath = appPath + "/" + configName
|
|
|
- logger.info(`文件地址:${exePath}-----${configPath}`);
|
|
|
+ // logger.info(`文件地址:${exePath}-----${configPath}`);
|
|
|
const command = exePath
|
|
|
const args = ['--config=' + configPath, '--port=' + app.port]
|
|
|
app.childProcess = spawn(command, args)
|
|
@@ -543,13 +561,25 @@ function robotAmount(app) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-// 定时清理停止状态的 机器人
|
|
|
-function delRobot(app) {
|
|
|
- // const platform = process.platform;
|
|
|
- // if (platform !== 'win32' && app.threadStatus === RobotStatus.STOPPED) {
|
|
|
- // var pid = app.childProcess.pid
|
|
|
- // delApp(app.id)
|
|
|
- // }
|
|
|
+// 定时清理机器人日志
|
|
|
+function delRobotLog(app) {
|
|
|
+ // 组装日志删除命令(最后修改时间在3天前的)
|
|
|
+ let deleteLogCommand = `sudo find logs` + app.port + ` -type f -mtime +3 -exec rm {} \\;`;
|
|
|
+ exec(deleteLogCommand, (error, stdout, stderr) => {
|
|
|
+ if (error) {
|
|
|
+ logger.error(`清理机器人日志命令执行失败~: ${deleteLogCommand} 错误:${error}`);
|
|
|
+ }
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+function delNodeLog() {
|
|
|
+ // 组装日志删除命令(最后修改时间在3天前的)
|
|
|
+ let deleteLogCommand = `sudo find logs/node -type f -mtime +3 -exec rm {} \\;`;
|
|
|
+ exec(deleteLogCommand, (error, stdout, stderr) => {
|
|
|
+ if (error) {
|
|
|
+ logger.error(`清理node日志命令执行失败~:错误:${error}`);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
//----------------------------------------------
|
|
@@ -559,7 +589,8 @@ module.exports = {
|
|
|
run,
|
|
|
closeApp,
|
|
|
restartApp,
|
|
|
- delRobot,
|
|
|
+ delRobotLog,
|
|
|
+ delNodeLog,
|
|
|
robotStatus,
|
|
|
robotAmount,
|
|
|
closeAppAll,
|