mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-24 15:30:16 +08:00
修复运行命令api任务日志路径
This commit is contained in:
parent
d8ae039b92
commit
c84908d7fa
|
@ -164,10 +164,12 @@ export default (app: Router) => {
|
||||||
try {
|
try {
|
||||||
const systemService = Container.get(SystemService);
|
const systemService = Container.get(SystemService);
|
||||||
const uniqPath = await getUniqPath(req.body.command);
|
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`;
|
const logPath = `${uniqPath}/${logTime}.log`;
|
||||||
res.setHeader('Content-type', 'application/octet-stream');
|
res.setHeader('Content-type', 'application/octet-stream');
|
||||||
await systemService.run(req.body, {
|
await systemService.run(
|
||||||
|
{ ...req.body, logPath },
|
||||||
|
{
|
||||||
onEnd: async (cp, endTime, diff) => {
|
onEnd: async (cp, endTime, diff) => {
|
||||||
res.end();
|
res.end();
|
||||||
},
|
},
|
||||||
|
@ -181,7 +183,8 @@ export default (app: Router) => {
|
||||||
const absolutePath = await handleLogPath(logPath);
|
const absolutePath = await handleLogPath(logPath);
|
||||||
fs.appendFileSync(absolutePath, `\n${message}`);
|
fs.appendFileSync(absolutePath, `\n${message}`);
|
||||||
},
|
},
|
||||||
});
|
},
|
||||||
|
);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return next(e);
|
return next(e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ const check = async (
|
||||||
const res = await promiseExec(
|
const res = await promiseExec(
|
||||||
`curl -sf http://localhost:${config.port}/api/system`,
|
`curl -sf http://localhost:${config.port}/api/system`,
|
||||||
);
|
);
|
||||||
console.log(res);
|
|
||||||
if (res.includes('200')) {
|
if (res.includes('200')) {
|
||||||
return callback(null, { status: 1 });
|
return callback(null, { status: 1 });
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)) {
|
if (!command.startsWith(TASK_COMMAND)) {
|
||||||
command = `${TASK_COMMAND} ${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 }) {
|
public async stop({ command }: { command: string }) {
|
||||||
|
|
|
@ -82,6 +82,7 @@ start_public() {
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
echo -e "=====> 开始检测"
|
echo -e "=====> 开始检测"
|
||||||
|
rm -rf ~/.pm2
|
||||||
npm i -g pnpm
|
npm i -g pnpm
|
||||||
patch_version
|
patch_version
|
||||||
pnpm add -g pm2 tsx
|
pnpm add -g pm2 tsx
|
||||||
|
|
|
@ -65,6 +65,11 @@ handle_log_path() {
|
||||||
[[ $log_dir_tmp_path ]] && log_dir_tmp="${log_dir_tmp_path}_${log_dir_tmp}"
|
[[ $log_dir_tmp_path ]] && log_dir_tmp="${log_dir_tmp_path}_${log_dir_tmp}"
|
||||||
log_dir="${log_dir_tmp%.*}${suffix}"
|
log_dir="${log_dir_tmp%.*}${suffix}"
|
||||||
log_path="$log_dir/$log_time.log"
|
log_path="$log_dir/$log_time.log"
|
||||||
|
|
||||||
|
if [[ $real_log_path != "${log_path}" ]]; then
|
||||||
|
log_path="$real_log_path"
|
||||||
|
fi
|
||||||
|
|
||||||
cmd=">> $dir_log/$log_path 2>&1"
|
cmd=">> $dir_log/$log_path 2>&1"
|
||||||
make_dir "$dir_log/$log_dir"
|
make_dir "$dir_log/$log_dir"
|
||||||
if [[ "$show_log" == "true" ]]; then
|
if [[ "$show_log" == "true" ]]; then
|
||||||
|
|
|
@ -13,8 +13,6 @@ const Error = () => {
|
||||||
const [data, setData] = useState('暂无日志');
|
const [data, setData] = useState('暂无日志');
|
||||||
const retryTimes = useRef(1);
|
const retryTimes = useRef(1);
|
||||||
|
|
||||||
console.log(retryTimes.current);
|
|
||||||
|
|
||||||
const getLog = (needLoading: boolean = true) => {
|
const getLog = (needLoading: boolean = true) => {
|
||||||
needLoading && setLoading(true);
|
needLoading && setLoading(true);
|
||||||
request
|
request
|
||||||
|
@ -24,9 +22,9 @@ const Error = () => {
|
||||||
return reloadUser();
|
return reloadUser();
|
||||||
}
|
}
|
||||||
if (retryTimes.current > 3) {
|
if (retryTimes.current > 3) {
|
||||||
|
setData(error?.details);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setData(error.details);
|
|
||||||
retryTimes.current += 1;
|
retryTimes.current += 1;
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
reloadUser();
|
reloadUser();
|
||||||
|
|
Loading…
Reference in New Issue
Block a user