Browse Source

(*)采集任务cron校验 启用禁用功能提交

master
peng.peng 2 years ago
parent
commit
ea65368c5e
  1. 54
      web/client/src/sections/metadataAcquisition/components/steps/postgre/stepThree.js
  2. 113
      web/client/src/sections/metadataAcquisition/containers/acquisitionTask.js
  3. 1
      web/package.json

54
web/client/src/sections/metadataAcquisition/components/steps/postgre/stepThree.js

@ -10,14 +10,57 @@ import {
ProFormDependency ProFormDependency
} from '@ant-design/pro-form'; } from '@ant-design/pro-form';
import { BellOutlined } from '@ant-design/icons' import { BellOutlined } from '@ant-design/icons'
import { parseHumanReadable } from 'cron-js-parser';
import '../../style.less'; import '../../style.less';
function StepThree(props) { function StepThree(props) {
const { prev, next, dataSourceFilter, editData } = props; const { prev, next, dataSourceFilter, editData } = props;
const formRef = React.createRef(); const formRef = React.createRef();
const initialValues = editData ? editData : { const initialValues = editData ? editData : {}
const testCron = () => {
try {
let lang = 'zh_CN' //english
let obj = {
atSeconds: [1, 5, 10],
runEveryXMins: {
startAt: 10,
every: 10
},
runEveryHourInRange: {
from: 2,
to: 20
},
isEveryDay: true,
atYears: [2020, 2022]
};
console.log(parseHumanReadable("0 15 10 ? * *", obj, lang))
} catch (err) {
console.log('Error: ' + err.message);
}
}
const checkCron = async (rule, value) => {
try {
let lang = 'zh_CN' //english
let obj = {
atSeconds: [1, 5, 10],
runEveryXMins: {
startAt: 10,
every: 10
},
runEveryHourInRange: {
from: 2,
to: 20
},
isEveryDay: true,
atYears: [2020, 2022]
};
console.log(parseHumanReadable(value, obj, lang))
return Promise.resolve();
} catch (err) {
return Promise.reject(new Error('请输入正确的cron表达式!'));
}
} }
const formItemLayout = { labelCol: { span: 4 }, wrapperCol: { span: 16 } }; const formItemLayout = { labelCol: { span: 4 }, wrapperCol: { span: 16 } };
return <> return <>
<div style={{ fontSize: 17 }}><BellOutlined style={{ marginRight: 15 }} />请输入该计划任务执行时间</div> <div style={{ fontSize: 17 }}><BellOutlined style={{ marginRight: 15 }} />请输入该计划任务执行时间</div>
@ -70,12 +113,13 @@ function StepThree(props) {
<ProFormText <ProFormText
width={'md'} width={'md'}
rules={[{ required: true, message: '请输入cron表达式' }, rules={[
{ max: 255, message: 'cron表达式长度不能大于255个字符' }, { required: true, message: '请输入cron表达式' },
{ validator: checkCron }
]} ]}
name="cron" name="cron"
label="请输入cron表达式" label="请输入cron表达式"
addonAfter={<Button type='primary'>测试</Button>} addonAfter={<Button type='primary' onClick={testCron}>测试</Button>}
/> />
<ProFormCheckbox <ProFormCheckbox

113
web/client/src/sections/metadataAcquisition/containers/acquisitionTask.js

@ -4,7 +4,7 @@ import { connect } from 'react-redux';
import ProTable from '@ant-design/pro-table'; import ProTable from '@ant-design/pro-table';
import moment from 'moment'; import moment from 'moment';
import TaskModal from '../components/taskModal'; import TaskModal from '../components/taskModal';
import { RELATION_DATABASE_TOOL_CONFIG } from '../constants/adapter'; import { parseHumanReadable } from 'cron-js-parser';
import './style.less'; import './style.less';
function AcquisitionTask(props) { function AcquisitionTask(props) {
@ -35,6 +35,62 @@ function AcquisitionTask(props) {
}); });
}; };
//cron表达式转中文
const transCron = (value) => {
try {
let lang = 'zh_CN' //english
let obj = {
atSeconds: [1, 5, 10],
runEveryXMins: {
startAt: 10,
every: 10
},
runEveryHourInRange: {
from: 2,
to: 20
},
isEveryDay: true,
atYears: [2020, 2022]
};
return (parseHumanReadable(value, obj, lang))
} catch (err) {
return '-'
}
}
const onFinish = (values) => {
const dataToSave = {
taskName: values?.taskName,
retryCount: values?.retryCount,
retryTime: values?.retryTime,
retried: values?.retried ? true : false,
dataSourceId: values?.dataSourceId,
cron: values?.cron,
}
if (editData) {
dispatch(actions.metadataAcquisition.modifyTask(editData?.id, dataToSave)).then(res => {
if (res.success) {
setVisible(false);
setEditData(null);
queryData();
}
})
} else {
dataToSave.enabled = true;
dataToSave.autoReleased = true;
dataToSave.storageStrategy = "增量";
dispatch(actions.metadataAcquisition.addTask(dataToSave)).then(res => {
if (res.success) {
setVisible(false);
setEditData(null);
queryData();
}
})
}
}
const columns = [ const columns = [
{ {
title: '任务名称', title: '任务名称',
@ -65,24 +121,40 @@ function AcquisitionTask(props) {
}, },
{ {
title: '执行周期', title: '执行周期',
dataIndex: 'dataSourceName', dataIndex: 'cron',
// render: (text, record) => {
// return transCron(record?.cron);
// }
}, },
{ {
title: '重复次数', title: '重复次数',
dataIndex: 'retryCount', dataIndex: 'retryCount',
}, },
{ {
title: '时间间隔', title: '时间间隔(分钟)',
dataIndex: 'retryTime', dataIndex: 'retryTime',
}, },
{ {
title: '操作', title: '操作',
width: 160, width: 300,
key: 'option', key: 'option',
valueType: 'option', valueType: 'option',
render: (text, record) => { render: (text, record) => {
const options = []; const options = [];
options.push(<a onClick={() => {
}} style={{ marginRight: 8 }}>立即执行</a>)
const enabledText = record?.enabled ? '禁用' : '启用';
options.push(<a onClick={() => {
dispatch(actions.metadataAcquisition.modifyTask(record?.id, { enabled: !record?.enabled }, '采集任务' + enabledText)).then(res => {
if (res.success) {
queryData();
}
})
}} style={{ marginRight: 8 }}>{enabledText}</a>)
options.push(<a onClick={() => { options.push(<a onClick={() => {
const adapterInfo = adapters?.find(x => x.id == record?.adapter) const adapterInfo = adapters?.find(x => x.id == record?.adapter)
setVisible(true) setVisible(true)
@ -107,39 +179,6 @@ function AcquisitionTask(props) {
}, },
]; ];
const onFinish = (values) => {
const dataToSave = {
taskName: values?.taskName,
retryCount: values?.retryCount,
retryTime: values?.retryTime,
retried: values?.retried ? true : false,
dataSourceId: values?.dataSourceId,
cron: values?.cron,
}
if (editData) {
dispatch(actions.metadataAcquisition.modifyTask(editData?.id, dataToSave)).then(res => {
if (res.success) {
setVisible(false);
setEditData(null);
queryData();
}
})
} else {
dataToSave.enabled = true;
dataToSave.autoReleased = true;
dataToSave.storageStrategy = "增量";
dispatch(actions.metadataAcquisition.addTask(dataToSave)).then(res => {
if (res.success) {
setVisible(false);
setEditData(null);
queryData();
}
})
}
}
return <Spin spinning={loading}> return <Spin spinning={loading}>
<Row className='protable-title'> <Row className='protable-title'>
<Col span={12}><Button type='primary' onClick={() => { setVisible(true) }}>新建</Button></Col> <Col span={12}><Button type='primary' onClick={() => { setVisible(true) }}>新建</Button></Col>

1
web/package.json

@ -73,6 +73,7 @@
"ali-oss": "^6.17.1", "ali-oss": "^6.17.1",
"antd": "^4.24.5", "antd": "^4.24.5",
"args": "^5.0.1", "args": "^5.0.1",
"cron-js-parser": "^1.0.17",
"cross-env": "^7.0.3", "cross-env": "^7.0.3",
"crypto-js": "^4.1.1", "crypto-js": "^4.1.1",
"echarts": "^5.4.1", "echarts": "^5.4.1",

Loading…
Cancel
Save