修复运行命令api任务日志路径

This commit is contained in:
whyour
2023-05-04 10:25:04 +08:00
parent d8ae039b92
commit c84908d7fa
6 changed files with 34 additions and 21 deletions
+18 -15
View File
@@ -164,24 +164,27 @@ export default (app: Router) => {
try {
const systemService = Container.get(SystemService);
const uniqPath = await getUniqPath(req.body.command);
const logTime = dayjs().format('YYYY-MM-DD-HH-mm-ss');
const logTime = dayjs().format('YYYY-MM-DD-HH-mm-ss-SSS');
const logPath = `${uniqPath}/${logTime}.log`;
res.setHeader('Content-type', 'application/octet-stream');
await systemService.run(req.body, {
onEnd: async (cp, endTime, diff) => {
res.end();
await systemService.run(
{ ...req.body, logPath },
{
onEnd: async (cp, endTime, diff) => {
res.end();
},
onError: async (message: string) => {
res.write(`\n${message}`);
const absolutePath = await handleLogPath(logPath);
fs.appendFileSync(absolutePath, `\n${message}`);
},
onLog: async (message: string) => {
res.write(`\n${message}`);
const absolutePath = await handleLogPath(logPath);
fs.appendFileSync(absolutePath, `\n${message}`);
},
},
onError: async (message: string) => {
res.write(`\n${message}`);
const absolutePath = await handleLogPath(logPath);
fs.appendFileSync(absolutePath, `\n${message}`);
},
onLog: async (message: string) => {
res.write(`\n${message}`);
const absolutePath = await handleLogPath(logPath);
fs.appendFileSync(absolutePath, `\n${message}`);
},
});
);
} catch (e) {
return next(e);
}
+1 -1
View File
@@ -13,7 +13,7 @@ const check = async (
const res = await promiseExec(
`curl -sf http://localhost:${config.port}/api/system`,
);
console.log(res);
if (res.includes('200')) {
return callback(null, { status: 1 });
}
+8 -2
View File
@@ -177,11 +177,17 @@ export default class SystemService {
}
}
public async run({ command }: { command: string }, callback: TaskCallbacks) {
public async run(
{ command, logPath }: { command: string; logPath: string },
callback: TaskCallbacks,
) {
if (!command.startsWith(TASK_COMMAND)) {
command = `${TASK_COMMAND} ${command}`;
}
this.scheduleService.runTask(`real_time=true ${command}`, callback);
this.scheduleService.runTask(
`real_log_path=${logPath} real_time=true ${command}`,
callback,
);
}
public async stop({ command }: { command: string }) {