From eddc03e29573d97916e7e5b6fdb899f42a92b78a Mon Sep 17 00:00:00 2001 From: whyour Date: Tue, 26 Sep 2023 22:51:33 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AE=9A=E6=97=B6=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E9=97=B4=E9=9A=94=E8=BE=83=E5=B0=8F=EF=BC=8C=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E7=8A=B6=E6=80=81=E4=B8=8D=E5=87=86=E7=A1=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/api/cron.ts | 5 ++--- back/services/cron.ts | 12 ++++++++++-- shell/share.sh | 2 +- src/layouts/index.less | 5 +++-- src/pages/crontab/logModal.tsx | 3 ++- src/pages/script/editModal.tsx | 5 +++-- src/pages/setting/checkUpdate.tsx | 4 ++-- src/pages/subscription/logModal.tsx | 3 ++- 8 files changed, 25 insertions(+), 14 deletions(-) diff --git a/back/api/cron.ts b/back/api/cron.ts index cd365132..2ef5c369 100644 --- a/back/api/cron.ts +++ b/back/api/cron.ts @@ -458,13 +458,12 @@ export default (app: Router) => { }), }), async (req: Request, res: Response, next: NextFunction) => { - const logger: Logger = Container.get('logger'); try { const cronService = Container.get(CronService); const data = await cronService.status({ ...req.body, - status: parseInt(req.body.status), - pid: parseInt(req.body.pid) || '', + status: req.body.status ? parseInt(req.body.status) : undefined, + pid: req.body.pid ? parseInt(req.body.pid) : undefined, }); return res.send({ code: 200, data }); } catch (e) { diff --git a/back/services/cron.ts b/back/services/cron.ts index 09876d04..078527fd 100644 --- a/back/services/cron.ts +++ b/back/services/cron.ts @@ -14,6 +14,8 @@ import cronClient from '../schedule/client'; import taskLimit from '../shared/pLimit'; import { spawn } from 'cross-spawn'; import dayjs from 'dayjs'; +import pickBy from 'lodash/pickBy'; +import omit from 'lodash/omit'; @Service() export default class CronService { @@ -89,7 +91,7 @@ export default class CronService { last_running_time: number; last_execution_time: number; }) { - const options: any = { + let options: any = { status, pid, log_path, @@ -99,7 +101,13 @@ export default class CronService { options.last_running_time = last_running_time; } - return await CrontabModel.update({ ...options }, { where: { id: ids } }); + for (const id of ids) { + const cron = await this.getDb({ id }); + if (status === CrontabStatus.idle && log_path !== cron.log_path) { + options = omit(options, ['status', 'log_path', 'pid']); + } + await CrontabModel.update({ ...pickBy(options, (v) => v === 0 || !!v) }, { where: { id } }); + } } public async remove(ids: number[]) { diff --git a/shell/share.sh b/shell/share.sh index aab2cb1c..1afa18d2 100755 --- a/shell/share.sh +++ b/shell/share.sh @@ -460,7 +460,7 @@ handle_task_after() { [[ "$diff_time" == 0 ]] && diff_time=1 - echo -e "\n\n## 执行结束... $end_time 耗时 $diff_time 秒     " + echo -e "\n## 执行结束... $end_time 耗时 $diff_time 秒     " [[ $ID ]] && update_cron "\"$ID\"" "1" "" "$log_path" "$begin_timestamp" "$diff_time" } diff --git a/src/layouts/index.less b/src/layouts/index.less index 06b86b80..5735c0de 100644 --- a/src/layouts/index.less +++ b/src/layouts/index.less @@ -25,8 +25,8 @@ body { } .ant-modal-body { - max-height: calc(90vh - 110px); - max-height: calc(90vh - var(--vh-offset, 110px)); + max-height: calc(80vh - 110px); + max-height: calc(80vh - var(--vh-offset, 110px)); overflow-y: auto; } @@ -181,6 +181,7 @@ body { .react-codemirror2, .CodeMirror { height: 100%; + overflow: auto; } } } diff --git a/src/pages/crontab/logModal.tsx b/src/pages/crontab/logModal.tsx index de995992..13ebe028 100644 --- a/src/pages/crontab/logModal.tsx +++ b/src/pages/crontab/logModal.tsx @@ -10,6 +10,7 @@ import { import { PageLoading } from '@ant-design/pro-layout'; import { logEnded } from '@/utils'; import { CrontabStatus } from './type'; +import Ansi from 'ansi-to-react'; const { Countdown } = Statistic; @@ -148,7 +149,7 @@ const CronLogModal = ({ : {} } > - {value} + {value} )}
diff --git a/src/pages/script/editModal.tsx b/src/pages/script/editModal.tsx index 87af6bde..5631aef8 100644 --- a/src/pages/script/editModal.tsx +++ b/src/pages/script/editModal.tsx @@ -16,6 +16,7 @@ import SettingModal from './setting'; import { useTheme } from '@/utils/hooks'; import { getEditorMode, logEnded } from '@/utils'; import WebSocketManager from '@/utils/websocket'; +import Ansi from 'ansi-to-react'; const { Option } = Select; @@ -116,7 +117,7 @@ const EditModal = ({ }, 300); } - setLog(p=>`${p}${_message}`); + setLog((p) => `${p}${_message}`); }, []); useEffect(() => { @@ -246,7 +247,7 @@ const EditModal = ({ padding: '0 15px', }} > - {log} + {log} { ), - content:
{lastLog}
, + content:
{lastLog}
, okText: intl.get('下载更新'), cancelText: intl.get('以后再说'), onOk() { @@ -102,7 +102,7 @@ const CheckUpdate = ({ systemInfo }: any) => { okButtonProps: { disabled: true }, title: intl.get('下载更新中...'), centered: true, - content:
{value}
, + content:
{value}
, }); }; diff --git a/src/pages/subscription/logModal.tsx b/src/pages/subscription/logModal.tsx index 921fb4a6..c45ea2e0 100644 --- a/src/pages/subscription/logModal.tsx +++ b/src/pages/subscription/logModal.tsx @@ -9,6 +9,7 @@ import { } from '@ant-design/icons'; import { PageLoading } from '@ant-design/pro-layout'; import { logEnded } from '@/utils'; +import Ansi from 'ansi-to-react'; const SubscriptionLogModal = ({ subscription, @@ -122,7 +123,7 @@ const SubscriptionLogModal = ({ : {} } > - {value} + {value} )}