From 364a58238978c587ffc979c5a86d4df6393bd9e4 Mon Sep 17 00:00:00 2001 From: whyour Date: Sun, 16 May 2021 18:19:40 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=88=B7=E6=96=B0cron?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E7=8A=B6=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/crontab/index.tsx | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/pages/crontab/index.tsx b/src/pages/crontab/index.tsx index b72a62ea..02bbe172 100644 --- a/src/pages/crontab/index.tsx +++ b/src/pages/crontab/index.tsx @@ -42,6 +42,8 @@ enum CrontabStatus { 'queued', } +const CrontabSort = [0, 3, 1]; + enum OperationName { '启用', '禁用', @@ -186,14 +188,30 @@ const Crontab = () => { const [logCron, setLogCron] = useState(); const [selectedRowIds, setSelectedRowIds] = useState([]); - const getCrons = () => { - setLoading(true); + const getCrons = (needLoading: boolean = true) => { + needLoading && setLoading(true); request .get(`${config.apiPrefix}crons?searchValue=${searchText}`) .then((data: any) => { - setValue(data.data.sort((a: any, b: any) => a.status - b.status)); + setValue( + data.data.sort( + (a: any, b: any) => CrontabSort[a.status] - CrontabSort[b.status], + ), + ); + const runningTasks = data.data.filter( + (x: any) => x.status !== CrontabStatus.idle, + ); + if ( + runningTasks.length > 0 && + !logCron && + location.pathname === '/crontab' + ) { + setTimeout(() => { + getCrons(false); + }, 5000); + } }) - .finally(() => setLoading(false)); + .finally(() => needLoading && setLoading(false)); }; const addCron = () => {