diff --git a/back/services/subscription.ts b/back/services/subscription.ts index 3a17a90e..035f86be 100644 --- a/back/services/subscription.ts +++ b/back/services/subscription.ts @@ -13,7 +13,6 @@ import { spawn, } from 'child_process'; import fs from 'fs'; -import cron_parser from 'cron-parser'; import { getFileContentByName, concurrentRun, diff --git a/src/pages/crontab/index.tsx b/src/pages/crontab/index.tsx index 47fc1ef0..7afceb7b 100644 --- a/src/pages/crontab/index.tsx +++ b/src/pages/crontab/index.tsx @@ -51,7 +51,7 @@ import ViewManageModal from './viewManageModal'; import { FilterValue, SorterResult } from 'antd/lib/table/interface'; import { SharedContext } from '@/layouts'; import useTableScrollHeight from '@/hooks/useTableScrollHeight'; -import { getCommandScript } from '@/utils'; +import { getCommandScript, parseCrontab } from '@/utils'; import { ColumnProps } from 'antd/lib/table'; import { VList } from 'virtuallist-antd'; @@ -446,10 +446,7 @@ const Crontab = () => { data.map((x) => { return { ...x, - nextRunTime: cron_parser - .parseExpression(x.schedule) - .next() - .toDate(), + nextRunTime: parseCrontab(x.schedule), }; }), ); @@ -736,10 +733,7 @@ const Crontab = () => { if (code === 200) { const index = value.findIndex((x) => x.id === cron.id); const result = [...value]; - data.nextRunTime = cron_parser - .parseExpression(data.schedule) - .next() - .toDate(); + data.nextRunTime = parseCrontab(data.schedule); if (index !== -1) { result.splice(index, 1, { ...cron, diff --git a/src/utils/index.ts b/src/utils/index.ts index 0145107b..7ca3cc39 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,4 +1,5 @@ import { LOG_END_SYMBOL } from './const'; +import cron_parser from 'cron-parser'; export default function browserType() { // 权重:系统 + 系统版本 > 平台 > 内核 + 载体 + 内核版本 + 载体版本 > 外壳 + 外壳版本 @@ -326,3 +327,14 @@ export function getCommandScript( } return [s, p]; } + +export function parseCrontab(schedule: string): Date { + try { + const time = cron_parser.parseExpression(schedule); + if (time) { + return time.next().toDate(); + } + } catch (error) {} + + return new Date('1970'); +}