修改定时规则类型

This commit is contained in:
whyour 2025-02-21 01:35:08 +08:00
parent 8173075b67
commit fa83761d27
7 changed files with 116 additions and 87 deletions

View File

@ -0,0 +1,13 @@
export enum ScheduleType {
BOOT = '@boot',
ONCE = '@once',
}
export type ScheduleValidator = (schedule?: string) => boolean;
export type CronSchedulerPayload = {
name: string;
id: string;
schedule: string;
command: string;
extra_schedules: Array<{ schedule: string }>;
};

View File

@ -22,6 +22,7 @@ import dayjs from 'dayjs';
import pickBy from 'lodash/pickBy'; import pickBy from 'lodash/pickBy';
import omit from 'lodash/omit'; import omit from 'lodash/omit';
import { writeFileWithLock } from '../shared/utils'; import { writeFileWithLock } from '../shared/utils';
import { ScheduleType } from '../interface/schedule';
@Service() @Service()
export default class CronService { export default class CronService {
@ -36,11 +37,11 @@ export default class CronService {
} }
private isOnceSchedule(schedule?: string) { private isOnceSchedule(schedule?: string) {
return schedule?.startsWith('@once'); return schedule?.startsWith(ScheduleType.ONCE);
} }
private isBootSchedule(schedule?: string) { private isBootSchedule(schedule?: string) {
return schedule?.startsWith('@boot'); return schedule?.startsWith(ScheduleType.BOOT);
} }
private isSpecialSchedule(schedule?: string) { private isSpecialSchedule(schedule?: string) {

View File

@ -1,8 +1,12 @@
import { Joi } from 'celebrate'; import { Joi } from 'celebrate';
import cron_parser from 'cron-parser'; import cron_parser from 'cron-parser';
import { ScheduleType } from '../interface/schedule';
const validateSchedule = (value: string, helpers: any) => { const validateSchedule = (value: string, helpers: any) => {
if (value.startsWith('@once') || value.startsWith('@boot')) { if (
value.startsWith(ScheduleType.ONCE) ||
value.startsWith(ScheduleType.BOOT)
) {
return value; return value;
} }

View File

@ -0,0 +1,13 @@
import { ScheduleType } from './type';
export const scheduleTypeMap = {
[ScheduleType.Normal]: '',
[ScheduleType.Once]: '@once',
[ScheduleType.Boot]: '@boot',
};
export const getScheduleType = (schedule?: string): ScheduleType => {
if (schedule?.startsWith('@once')) return ScheduleType.Once;
if (schedule?.startsWith('@boot')) return ScheduleType.Boot;
return ScheduleType.Normal;
};

View File

@ -1,64 +1,64 @@
import intl from 'react-intl-universal'; import useTableScrollHeight from '@/hooks/useTableScrollHeight';
import React, { useState, useEffect, useRef, useMemo } from 'react'; import { SharedContext } from '@/layouts';
import { getCommandScript, getCrontabsNextDate } from '@/utils';
import config from '@/utils/config';
import { diffTime } from '@/utils/date';
import { request } from '@/utils/http';
import {
CheckCircleOutlined,
CheckOutlined,
ClockCircleOutlined,
CloseCircleOutlined,
CopyOutlined,
DeleteOutlined,
DownOutlined,
EditOutlined,
EllipsisOutlined,
FieldTimeOutlined,
Loading3QuartersOutlined,
PlusOutlined,
PushpinOutlined,
SettingOutlined,
StopOutlined,
UnorderedListOutlined
} from '@ant-design/icons';
import { PageContainer } from '@ant-design/pro-layout';
import { history, useOutletContext } from '@umijs/max';
import { import {
Button, Button,
Dropdown,
Input,
MenuProps,
message, message,
Modal, Modal,
Table,
Tag,
Space, Space,
Tooltip, Table,
Dropdown,
Menu,
Typography,
Input,
Popover,
Tabs,
TablePaginationConfig, TablePaginationConfig,
MenuProps, Tabs,
Tag,
Typography
} from 'antd'; } from 'antd';
import {
ClockCircleOutlined,
Loading3QuartersOutlined,
CloseCircleOutlined,
FileTextOutlined,
EllipsisOutlined,
PlayCircleOutlined,
CheckCircleOutlined,
EditOutlined,
StopOutlined,
DeleteOutlined,
PauseCircleOutlined,
FieldTimeOutlined,
PushpinOutlined,
DownOutlined,
SettingOutlined,
PlusOutlined,
UnorderedListOutlined,
CheckOutlined,
CopyOutlined,
} from '@ant-design/icons';
import config from '@/utils/config';
import { PageContainer } from '@ant-design/pro-layout';
import { request } from '@/utils/http';
import CronModal, { CronLabelModal } from './modal';
import CronLogModal from './logModal';
import CronDetailModal from './detail';
import { diffTime } from '@/utils/date';
import { history, useOutletContext } from '@umijs/max';
import './index.less';
import ViewCreateModal from './viewCreateModal';
import ViewManageModal from './viewManageModal';
import { FilterValue, SorterResult } from 'antd/lib/table/interface';
import { SharedContext } from '@/layouts';
import useTableScrollHeight from '@/hooks/useTableScrollHeight';
import { getCommandScript, getCrontabsNextDate, parseCrontab } from '@/utils';
import { ColumnProps } from 'antd/lib/table'; import { ColumnProps } from 'antd/lib/table';
import { useVT } from 'virtualizedtableforantd4'; import { FilterValue, SorterResult } from 'antd/lib/table/interface';
import { ICrontab, OperationName, OperationPath, CrontabStatus } from './type';
import Name from '@/components/name';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import { noop, omit } from 'lodash'; import { noop, omit } from 'lodash';
import React, { useEffect, useRef, useState } from 'react';
import intl from 'react-intl-universal';
import { useVT } from 'virtualizedtableforantd4';
import { getScheduleType } from './const';
import CronDetailModal from './detail';
import './index.less';
import CronLogModal from './logModal';
import CronModal, { CronLabelModal } from './modal';
import {
CrontabStatus,
ICrontab,
OperationName,
OperationPath,
ScheduleType,
} from './type';
import ViewCreateModal from './viewCreateModal';
import ViewManageModal from './viewManageModal';
const { Text, Paragraph, Link } = Typography; const { Text, Paragraph, Link } = Typography;
const { Search } = Input; const { Search } = Input;
@ -263,7 +263,7 @@ const Crontab = () => {
}, },
}, },
render: (text, record) => { render: (text, record) => {
return record.nextRunTime return record.nextRunTime
? dayjs(record.nextRunTime).format('YYYY-MM-DD HH:mm:ss') ? dayjs(record.nextRunTime).format('YYYY-MM-DD HH:mm:ss')
: '-'; : '-';
}, },
@ -398,10 +398,11 @@ const Crontab = () => {
setValue( setValue(
data.map((x) => { data.map((x) => {
const specialSchedules = ['@once', '@boot']; const scheduleType = getScheduleType(x.schedule);
const nextRunTime = specialSchedules.includes(x.schedule) const nextRunTime =
? null scheduleType === ScheduleType.Normal
: getCrontabsNextDate(x.schedule, x.extra_schedules); ? getCrontabsNextDate(x.schedule, x.extra_schedules)
: null;
return { return {
...x, ...x,
nextRunTime, nextRunTime,
@ -812,7 +813,9 @@ const Crontab = () => {
useEffect(() => { useEffect(() => {
if (viewConf && enabledCronViews && enabledCronViews.length > 0) { if (viewConf && enabledCronViews && enabledCronViews.length > 0) {
const view = enabledCronViews.slice(SHOW_TAB_COUNT).find((x) => x.id === viewConf.id); const view = enabledCronViews
.slice(SHOW_TAB_COUNT)
.find((x) => x.id === viewConf.id);
setMoreMenuActive(!!view); setMoreMenuActive(!!view);
} }
}, [viewConf, enabledCronViews]); }, [viewConf, enabledCronViews]);

View File

@ -1,29 +1,13 @@
import intl from 'react-intl-universal';
import React, { useEffect, useState } from 'react';
import { Modal, message, Input, Form, Button, Space, Select } from 'antd';
import { request } from '@/utils/http';
import config from '@/utils/config';
import cronParse from 'cron-parser';
import EditableTagGroup from '@/components/tag'; import EditableTagGroup from '@/components/tag';
import config from '@/utils/config';
import { request } from '@/utils/http';
import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons'; import { MinusCircleOutlined, PlusOutlined } from '@ant-design/icons';
import { Button, Form, Input, Modal, Select, Space, message } from 'antd';
enum ScheduleType { import cronParse from 'cron-parser';
Normal = 'normal', import { useEffect, useState } from 'react';
Once = 'once', import intl from 'react-intl-universal';
Boot = 'boot', import { getScheduleType, scheduleTypeMap } from './const';
} import { ScheduleType } from './type';
const scheduleTypeMap = {
[ScheduleType.Normal]: '',
[ScheduleType.Once]: '@once',
[ScheduleType.Boot]: '@boot',
};
const getScheduleType = (schedule?: string): ScheduleType => {
if (schedule?.startsWith('@once')) return ScheduleType.Once;
if (schedule?.startsWith('@boot')) return ScheduleType.Boot;
return ScheduleType.Normal;
};
const CronModal = ({ const CronModal = ({
cron, cron,
@ -85,7 +69,11 @@ const CronModal = ({
}; };
const renderScheduleOptions = () => ( const renderScheduleOptions = () => (
<Select defaultValue={scheduleType} value={scheduleType} onChange={handleScheduleTypeChange}> <Select
defaultValue={scheduleType}
value={scheduleType}
onChange={handleScheduleTypeChange}
>
<Select.Option value={ScheduleType.Normal}> <Select.Option value={ScheduleType.Normal}>
{intl.get('常规定时')} {intl.get('常规定时')}
</Select.Option> </Select.Option>
@ -336,4 +324,5 @@ const CronLabelModal = ({
); );
}; };
export { CronModal as default, CronLabelModal }; export { CronLabelModal, CronModal as default };

View File

@ -36,5 +36,11 @@ export interface ICrontab {
last_execution_time?: number; last_execution_time?: number;
nextRunTime: Date; nextRunTime: Date;
sub_id: number; sub_id: number;
extra_schedules?: Array<{ schedule: string; }>; extra_schedules?: Array<{ schedule: string }>;
}
export enum ScheduleType {
Normal = 'normal',
Once = 'once',
Boot = 'boot',
} }