修复cron日志显示

This commit is contained in:
whyour 2021-04-10 19:50:52 +08:00
parent f9c299cfbe
commit 9a1891c909
3 changed files with 36 additions and 10 deletions

View File

@ -105,7 +105,7 @@ function Npm_InstallSub() {
npm install --no-save --registry=https://registry.npm.taobao.org || npm install --no-save npm install --no-save --registry=https://registry.npm.taobao.org || npm install --no-save
else else
echo -e "检测到本机安装了 yarn使用 yarn 替代 npm...\n" echo -e "检测到本机安装了 yarn使用 yarn 替代 npm...\n"
yarn install --registry=https://registry.npm.taobao.org || yarn install yarn install --registry=https://registry.npm.taobao.org --network-timeout 1000000000 || yarn install
fi fi
} }

View File

@ -120,8 +120,7 @@ const Crontab = () => {
<Tooltip title="日志"> <Tooltip title="日志">
<a <a
onClick={() => { onClick={() => {
setLogCron(record); setLogCron({ ...record, timestamp: Date.now() });
setIsLogModalVisible(true);
}} }}
> >
<FileTextOutlined /> <FileTextOutlined />
@ -386,6 +385,12 @@ const Crontab = () => {
.finally(() => setLoading(false)); .finally(() => setLoading(false));
}; };
useEffect(() => {
if (logCron) {
setIsLogModalVisible(true);
}
}, [logCron]);
useEffect(() => { useEffect(() => {
getCrons(); getCrons();
}, [searchText]); }, [searchText]);

View File

@ -20,12 +20,37 @@ const CronLogModal = ({
}) => { }) => {
const [value, setValue] = useState<string>('启动中...'); const [value, setValue] = useState<string>('启动中...');
const [logTimer, setLogTimer] = useState<any>(); const [logTimer, setLogTimer] = useState<any>();
const [loading, setLoading] = useState<any>(true);
const getCronLog = () => { const getCronLog = (isFirst?: boolean) => {
if (isFirst) {
setLoading(true);
}
request request
.get(`${config.apiPrefix}crons/${cron._id}/log`) .get(`${config.apiPrefix}crons/${cron._id}/log`)
.then((data: any) => { .then((data: any) => {
setValue(data.data || '暂无日志'); const log = data.data as string;
setValue(log || '暂无日志');
if (log.includes('执行结束')) {
if (logTimer) {
clearInterval(logTimer);
}
} else {
const timer = setInterval(() => {
getCronLog();
}, 2000);
setLogTimer(timer);
}
})
.catch(() => {
if (logTimer) {
clearInterval(logTimer);
}
})
.finally(() => {
if (isFirst) {
setLoading(false);
}
}); });
}; };
@ -36,10 +61,7 @@ const CronLogModal = ({
useEffect(() => { useEffect(() => {
if (cron) { if (cron) {
const timer = setInterval(() => { getCronLog(true);
getCronLog();
}, 2000);
setLogTimer(timer);
} }
}, [cron]); }, [cron]);
@ -50,7 +72,6 @@ const CronLogModal = ({
forceRender forceRender
onOk={() => cancel()} onOk={() => cancel()}
onCancel={() => cancel()} onCancel={() => cancel()}
destroyOnClose
> >
<pre style={{ whiteSpace: 'pre-wrap', wordWrap: 'break-word' }}> <pre style={{ whiteSpace: 'pre-wrap', wordWrap: 'break-word' }}>
{value} {value}