修复cron日志获取逻辑

This commit is contained in:
whyour
2021-04-11 10:31:30 +08:00
parent 7105952670
commit 2a7d298f05
2 changed files with 4 additions and 16 deletions
+3 -15
View File
@@ -19,7 +19,6 @@ const CronLogModal = ({
handleCancel: () => void;
}) => {
const [value, setValue] = useState<string>('启动中...');
const [logTimer, setLogTimer] = useState<any>();
const [loading, setLoading] = useState<any>(true);
const getCronLog = (isFirst?: boolean) => {
@@ -31,20 +30,10 @@ const CronLogModal = ({
.then((data: any) => {
const log = data.data as string;
setValue(log || '暂无日志');
if (log.includes('执行结束')) {
if (logTimer) {
clearInterval(logTimer);
}
} else if (isFirst) {
const timer = setInterval(() => {
if (log && log.includes('执行结束')) {
setTimeout(() => {
getCronLog();
}, 2000);
setLogTimer(timer);
}
})
.catch(() => {
if (logTimer) {
clearInterval(logTimer);
}
})
.finally(() => {
@@ -55,7 +44,6 @@ const CronLogModal = ({
};
const cancel = () => {
clearInterval(logTimer);
handleCancel();
};
@@ -74,7 +62,7 @@ const CronLogModal = ({
onCancel={() => cancel()}
>
<pre style={{ whiteSpace: 'pre-wrap', wordWrap: 'break-word' }}>
{value}
{!loading && value}
</pre>
</Modal>
);