diff --git a/back/services/cron.ts b/back/services/cron.ts index 4eb24a61..5ea4dcfc 100644 --- a/back/services/cron.ts +++ b/back/services/cron.ts @@ -124,7 +124,7 @@ export default class CronService { fs.writeFileSync(logFile, `开始执行...\n\n${new Date().toString()}\n`); let cmdStr = res.command; - if (res.command.startsWith('js')) { + if (res.command.startsWith('js') && !res.command.endsWith('now')) { cmdStr = `${res.command} now`; } else if (/&& (.*) >>/.test(res.command)) { cmdStr = res.command.match(/&& (.*) >>/)[1]; diff --git a/src/pages/crontab/logModal.tsx b/src/pages/crontab/logModal.tsx index a61ccbb5..4fc03f14 100644 --- a/src/pages/crontab/logModal.tsx +++ b/src/pages/crontab/logModal.tsx @@ -19,7 +19,6 @@ const CronLogModal = ({ handleCancel: () => void; }) => { const [value, setValue] = useState('启动中...'); - const [logTimer, setLogTimer] = useState(); const [loading, setLoading] = useState(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()} >
-        {value}
+        {!loading && value}
       
);