修复 command-run 接口日志绑定

This commit is contained in:
whyour 2025-07-12 20:29:44 +08:00
parent 0587644a6b
commit 50769c43dd
6 changed files with 79 additions and 83 deletions

View File

@ -279,14 +279,14 @@ export default (app: Router) => {
res.end();
},
onError: async (message: string) => {
res.write(`\n${message}`);
res.write(message);
const absolutePath = await handleLogPath(logPath);
await fs.appendFile(absolutePath, `\n${message}`);
await fs.appendFile(absolutePath, message);
},
onLog: async (message: string) => {
res.write(`\n${message}`);
res.write(message);
const absolutePath = await handleLogPath(logPath);
await fs.appendFile(absolutePath, `\n${message}`);
await fs.appendFile(absolutePath, message);
},
},
);

View File

@ -573,7 +573,7 @@ export default class CronService {
return typeof doc.status === 'number' &&
[CrontabStatus.queued, CrontabStatus.running].includes(doc.status)
? '运行中...'
: '任务空闲中';
: '日志不存在...';
}
}

View File

@ -47,7 +47,7 @@ export default class SystemService {
@Inject('logger') private logger: winston.Logger,
private scheduleService: ScheduleService,
private sockService: SockService,
) {}
) { }
public async getSystemConfig() {
const doc = await this.getDb({ type: AuthDataType.systemConfig });
@ -287,7 +287,7 @@ export default class SystemService {
);
const text = await body.text();
lastVersionContent = parseContentVersion(text);
} catch (error) {}
} catch (error) { }
if (!lastVersionContent) {
lastVersionContent = currentVersionContent;
@ -401,11 +401,12 @@ 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, {
const logPathPrefix = logPath ? `real_log_path=${logPath}` : ''
this.scheduleService.runTask(`${logPathPrefix} real_time=true ${command}`, callback, {
command,
id: command.replace(/ /g, '-'),
runOrigin: 'system',
@ -442,8 +443,7 @@ export default class SystemService {
}
const dataPaths = dataDirs.map((dir) => `data/${dir}`);
await promiseExec(
`cd ${config.dataPath} && cd ../ && tar -zcvf ${
config.dataTgzFile
`cd ${config.dataPath} && cd ../ && tar -zcvf ${config.dataTgzFile
} ${dataPaths.join(' ')}`,
);
res.download(config.dataTgzFile);
@ -537,7 +537,7 @@ export default class SystemService {
try {
const finalPath = path.join(config.dependenceCachePath, type);
await fs.promises.rm(finalPath, { recursive: true });
} catch (error) {}
} catch (error) { }
return { code: 200 };
}
}

View File

@ -2,13 +2,9 @@
echo -e "开始发布"
echo -e "切换master分支"
git checkout master
echo -e "合并develop代码"
git merge origin/develop
echo -e "提交master代码"
git push
git branch -D master
git checkout -b master
git push --set-upstream origin master -f
echo -e "更新cdn文件"
ts-node-transpile-only sample/tool.ts

View File

@ -1,5 +1,5 @@
import intl from 'react-intl-universal';
import React, { useEffect, useRef, useState } from 'react';
import intl from "react-intl-universal";
import React, { useEffect, useRef, useState } from "react";
import {
Modal,
message,
@ -8,17 +8,17 @@ import {
Statistic,
Button,
Typography,
} from 'antd';
import { request } from '@/utils/http';
import config from '@/utils/config';
} from "antd";
import { request } from "@/utils/http";
import config from "@/utils/config";
import {
Loading3QuartersOutlined,
CheckCircleOutlined,
} from '@ant-design/icons';
import { PageLoading } from '@ant-design/pro-layout';
import { logEnded } from '@/utils';
import { CrontabStatus } from './type';
import Ansi from 'ansi-to-react';
} from "@ant-design/icons";
import { PageLoading } from "@ant-design/pro-layout";
import { logEnded } from "@/utils";
import { CrontabStatus } from "./type";
import Ansi from "ansi-to-react";
const { Countdown } = Statistic;
@ -33,7 +33,7 @@ const CronLogModal = ({
data?: string;
logUrl?: string;
}) => {
const [value, setValue] = useState<string>(intl.get('启动中...'));
const [value, setValue] = useState<string>(intl.get("启动中..."));
const [loading, setLoading] = useState<any>(true);
const [executing, setExecuting] = useState<any>(true);
const [isPhone, setIsPhone] = useState(false);
@ -49,15 +49,15 @@ const CronLogModal = ({
.then(({ code, data }) => {
if (
code === 200 &&
localStorage.getItem('logCron') === uniqPath &&
localStorage.getItem("logCron") === uniqPath &&
data !== value
) {
const log = data as string;
setValue(log || intl.get('暂无日志'));
setValue(log || intl.get("暂无日志"));
const hasNext = Boolean(
log && !logEnded(log) && !log.includes('任务未运行'),
log && !logEnded(log) && !log.includes("日志不存在"),
);
if (!hasNext && !logEnded(value) && value !== intl.get('启动中...')) {
if (!hasNext && !logEnded(value) && value !== intl.get("启动中...")) {
setTimeout(() => {
autoScroll();
});
@ -85,13 +85,13 @@ const CronLogModal = ({
setTimeout(() => {
document
.querySelector('#log-flag')!
.scrollIntoView({ behavior: 'smooth' });
.querySelector("#log-flag")
?.scrollIntoView({ behavior: "smooth" });
}, 600);
};
const cancel = () => {
localStorage.removeItem('logCron');
localStorage.removeItem("logCron");
handleCancel();
};
@ -107,7 +107,7 @@ const CronLogModal = ({
const titleElement = () => {
return (
<div style={{ display: 'flex', alignItems: 'center' }}>
<div style={{ display: "flex", alignItems: "center" }}>
{(executing || loading) && <Loading3QuartersOutlined spin />}
{!executing && !loading && <CheckCircleOutlined />}
<Typography.Text ellipsis={true} style={{ marginLeft: 5 }}>
@ -144,7 +144,7 @@ const CronLogModal = ({
onCancel={() => cancel()}
footer={[
<Button type="primary" onClick={() => cancel()}>
{intl.get('知道了')}
{intl.get("知道了")}
</Button>,
]}
>
@ -156,7 +156,7 @@ const CronLogModal = ({
style={
isPhone
? {
fontFamily: 'Source Code Pro',
fontFamily: "Source Code Pro",
zoom: 0.83,
}
: {}

View File

@ -1,23 +1,23 @@
import { disableBody } from '@/utils';
import config from '@/utils/config';
import { request } from '@/utils/http';
import WebSocketManager from '@/utils/websocket';
import Ansi from 'ansi-to-react';
import { Button, Modal, Statistic, message } from 'antd';
import { useCallback, useEffect, useRef, useState } from 'react';
import intl from 'react-intl-universal';
import { disableBody } from "@/utils";
import config from "@/utils/config";
import { request } from "@/utils/http";
import WebSocketManager from "@/utils/websocket";
import Ansi from "ansi-to-react";
import { Button, Modal, Statistic, message } from "antd";
import { useCallback, useEffect, useRef, useState } from "react";
import intl from "react-intl-universal";
const { Countdown } = Statistic;
const CheckUpdate = ({ systemInfo }: any) => {
const [updateLoading, setUpdateLoading] = useState(false);
const [value, setValue] = useState('');
const [value, setValue] = useState("");
const modalRef = useRef<any>();
const checkUpgrade = () => {
if (updateLoading) return;
setUpdateLoading(true);
message.loading(intl.get('检查更新中...'), 0);
message.loading(intl.get("检查更新中..."), 0);
request
.put(`${config.apiPrefix}system/update-check`)
.then(({ code, data }) => {
@ -42,22 +42,22 @@ const CheckUpdate = ({ systemInfo }: any) => {
const showForceUpdateModal = (data: any) => {
Modal.confirm({
width: 500,
title: intl.get('更新'),
title: intl.get("更新"),
content: (
<>
<div>{intl.get('已经是最新版了!')}</div>
<div>{intl.get("已经是最新版了!")}</div>
<div style={{ fontSize: 12, fontWeight: 400, marginTop: 5 }}>
{intl.get('青龙')} {data.lastVersion}{' '}
{intl.get('是目前检测到的最新可用版本了。')}
{intl.get("青龙")} {data.lastVersion}{" "}
{intl.get("是目前检测到的最新可用版本了。")}
</div>
</>
),
okText: intl.get('重新下载'),
okText: intl.get("重新下载"),
onOk() {
showUpdatingModal();
request
.put(`${config.apiPrefix}system/update`)
.then((_data: any) => {})
.then((_data: any) => { })
.catch((error: any) => {
console.log(error);
});
@ -71,10 +71,10 @@ const CheckUpdate = ({ systemInfo }: any) => {
width: 500,
title: (
<>
<div>{intl.get('更新可用')}</div>
<div>{intl.get("更新可用")}</div>
<div style={{ fontSize: 12, fontWeight: 400, marginTop: 5 }}>
{intl.get('新版本')} {lastVersion}{' '}
{intl.get('可用,你使用的版本为')} {systemInfo.version}
{intl.get("新版本")} {lastVersion}{" "}
{intl.get("可用,你使用的版本为")} {systemInfo.version}
</div>
</>
),
@ -83,13 +83,13 @@ const CheckUpdate = ({ systemInfo }: any) => {
<Ansi>{lastLog}</Ansi>
</pre>
),
okText: intl.get('下载更新'),
cancelText: intl.get('以后再说'),
okText: intl.get("下载更新"),
cancelText: intl.get("以后再说"),
onOk() {
showUpdatingModal();
request
.put(`${config.apiPrefix}system/update`)
.then((_data: any) => {})
.then((_data: any) => { })
.catch((error: any) => {
console.log(error);
});
@ -98,14 +98,14 @@ const CheckUpdate = ({ systemInfo }: any) => {
};
const showUpdatingModal = () => {
setValue('');
setValue("");
modalRef.current = Modal.info({
width: 600,
maskClosable: false,
closable: false,
keyboard: false,
okButtonProps: { disabled: true },
title: intl.get('下载更新中...'),
title: intl.get("下载更新中..."),
centered: true,
content: (
<pre>
@ -122,13 +122,13 @@ const CheckUpdate = ({ systemInfo }: any) => {
message.success({
content: (
<span>
{intl.get('系统将在')}
{intl.get("系统将在")}
<Countdown
className="inline-countdown"
format="ss"
value={Date.now() + 1000 * 30}
/>
{intl.get('秒后自动刷新')}
{intl.get("秒后自动刷新")}
</span>
),
duration: 30,
@ -147,12 +147,12 @@ const CheckUpdate = ({ systemInfo }: any) => {
Modal.confirm({
width: 600,
maskClosable: false,
title: intl.get('确认重启'),
title: intl.get("确认重启"),
centered: true,
content: intl.get('系统安装包下载成功,确认重启'),
okText: intl.get('重启'),
content: intl.get("系统安装包下载成功,确认重启"),
okText: intl.get("重启"),
onOk() {
reloadSystem('system');
reloadSystem("system");
},
onCancel() {
modalRef.current.update({
@ -166,7 +166,7 @@ const CheckUpdate = ({ systemInfo }: any) => {
useEffect(() => {
if (!value) return;
const updateFailed = value.includes('失败,请检查');
const updateFailed = value.includes("失败,请检查");
modalRef.current.update({
maskClosable: updateFailed,
@ -185,19 +185,19 @@ const CheckUpdate = ({ systemInfo }: any) => {
const handleMessage = useCallback((payload: any) => {
let { message: _message } = payload;
const updateFailed = _message.includes('失败,请检查');
const updateFailed = _message.includes("失败,请检查");
if (updateFailed) {
message.error(intl.get('更新失败,请检查网络及日志或稍后再试'));
message.error(intl.get("更新失败,请检查网络及日志或稍后再试"));
}
setTimeout(() => {
document
.querySelector('#log-identifier')!
.scrollIntoView({ behavior: 'smooth' });
.querySelector("#log-identifier")
?.scrollIntoView({ behavior: "smooth" });
}, 600);
if (_message.includes('更新包下载成功')) {
if (_message.includes("更新包下载成功")) {
setTimeout(() => {
showReloadModal();
}, 1000);
@ -208,24 +208,24 @@ const CheckUpdate = ({ systemInfo }: any) => {
useEffect(() => {
const ws = WebSocketManager.getInstance();
ws.subscribe('updateSystemVersion', handleMessage);
ws.subscribe("updateSystemVersion", handleMessage);
return () => {
ws.unsubscribe('updateSystemVersion', handleMessage);
ws.unsubscribe("updateSystemVersion", handleMessage);
};
}, []);
return (
<>
<Button type="primary" onClick={checkUpgrade}>
{intl.get('检查更新')}
{intl.get("检查更新")}
</Button>
<Button
type="primary"
onClick={() => reloadSystem('reload')}
onClick={() => reloadSystem("reload")}
style={{ marginLeft: 8 }}
>
{intl.get('重新启动')}
{intl.get("重新启动")}
</Button>
</>
);