Browse Source

(*)采集任务立即执行功能提交

master
peng.peng 2 years ago
parent
commit
85736afa06
  1. 10
      api/app/lib/controllers/metadataAcquisition/task.js
  2. 4
      api/app/lib/routes/metadataAcquisition/task.js
  3. 15
      web/client/src/sections/metadataAcquisition/actions/task.js
  4. 184
      web/client/src/sections/metadataAcquisition/containers/acquisitionLog.js
  5. 12
      web/client/src/sections/metadataAcquisition/containers/acquisitionTask.js
  6. 2
      web/client/src/utils/webapi.js

10
api/app/lib/controllers/metadataAcquisition/task.js

@ -133,6 +133,12 @@ function deleteAcquisitionTask(app) {
try {
const models = ctx.fs.dc.models;
const { id } = ctx.params;
await models.AcquisitionLog.destroy({
where: {
task: id
}
})
const task = await models.AcquisitionTask.destroy({
where: {
id: id
@ -156,13 +162,13 @@ function deleteAcquisitionTask(app) {
}
// 采集任务立即执行一次
function addAcquisitionTask(app) {
function runAcqTask(app) {
return async function (ctx, next) {
const models = ctx.fs.dc.models;
try {
const { id } = ctx.request.body
const task = await models.AcquisitionTask.findOne({ where: { id, id } });
const task = await models.AcquisitionTask.findOne({ where: { id: id } });
if (task) {
await handleTask(app, task);
ctx.status = 204;

4
api/app/lib/routes/metadataAcquisition/task.js

@ -20,7 +20,7 @@ module.exports = function (app, router, opts, AuthCode) {
router.del('acq/task/:id', task.deleteAcquisitionTask(app))
//任务立即执行
app.fs.api.logAttr['POST/acq/task/run'] = { content: '任务立即执行', visible: true };
router.put('/acq/task/run', task.runAcqTask(app))
app.fs.api.logAttr['POST/run/acq/task'] = { content: '任务立即执行', visible: true };
router.post('/run/acq/task', task.runAcqTask(app))
};

15
web/client/src/sections/metadataAcquisition/actions/task.js

@ -8,7 +8,7 @@ export function addTask(params, msg) {
type: 'post',
data: params,
dispatch,
actionType: 'ADD_DATSOURCE',
actionType: 'ADD_ACQ_TASK',
url: ApiTable.addTask,
msg: {
option: msg || '新增采集任务',
@ -53,4 +53,17 @@ export function modifyTask(id, params, msg) {
});
}
export function runTask(params, msg) {
return (dispatch) => basicAction({
type: 'post',
data: params,
dispatch,
actionType: 'RUN_ACQ_TASK',
url: ApiTable.runTask,
msg: {
option: msg || '任务执行',
},
});
}

184
web/client/src/sections/metadataAcquisition/containers/acquisitionLog.js

@ -1,7 +1,185 @@
import React, { useEffect, useState } from 'react'
import { Spin, Popconfirm, Tree, Row, Col, Button, Input, Table } from 'antd';
import { connect } from 'react-redux';
import ProTable from '@ant-design/pro-table';
import moment from 'moment';
function AcquisitionLog (props) {
return <>采集日志</>
import './style.less';
function AcquisitionLog(props) {
const { loading, clientHeight, actions, dispatch, dataSources, adapters, tasks } = props;
const [pageSize, setPageSize] = useState(10);
const [currentPage, setCurrentPage] = useState(1);
const [searchValue, setSearchValue] = useState('')
const queryData = (search) => {
const query = {
// limit: search ? 10 : pageSize || 10,
// page: search ? 1 : currentPage || 1,
taskName: searchValue
}
dispatch(actions.metadataAcquisition.getTasks(query));
}
useEffect(() => {
dispatch(actions.metadataAcquisition.getDataSources());
dispatch(actions.metadataAcquisition.getAdapters())
queryData();
}, [pageSize, currentPage]);
const columns = [
{
title: '任务名称',
dataIndex: 'taskName',
},
{
title: '数据源名称',
dataIndex: 'dataSourceName',
render: (text, record) => {
return record?.dataSource?.name
}
},
{
title: '适配器类型',
dataIndex: 'adapter',
render: (text, record) => {
const adapterInfo = record?.dataSource?.adapter
return adapterInfo?.adapterName
}
},
{
title: '采集方式',
dataIndex: 'control',
render: (text, record) => {
const adapterInfo = record?.dataSource?.adapter
return adapterInfo?.mode
}
},
{
title: '执行周期',
dataIndex: 'cron',
// render: (text, record) => {
// return transCron(record?.cron);
// }
},
{
title: '重复次数',
dataIndex: 'retryCount',
},
{
title: '时间间隔(分钟)',
dataIndex: 'retryTime',
},
{
title: '操作',
width: 300,
key: 'option',
valueType: 'option',
render: (text, record) => {
const options = [];
options.push(<a onClick={() => {
const param = { id: record.id }
dispatch(actions.metadataAcquisition.runTask(param))
}} 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={() => {
const adapterInfo = adapters?.find(x => x.id == record?.adapter)
setVisible(true)
record.adapterInfo = adapterInfo
setEditData(record)
}} style={{ marginRight: 8 }}>编辑</a>)
//判断数据源下是否有任务 有任务提示需要先删除任务再删除数据源
options.push(
<Popconfirm
key="del"
placement="top"
title={<><div>是否确认删除该采集任务</div>
<div>(将同步删除该任务采集日志)</div></>}
onConfirm={() => handleDelete(record.id)}
okText="是"
cancelText="否"
>
<a>删除</a>
</Popconfirm>)
return options;
},
},
];
return <Spin spinning={loading}>
<Row className='protable-title'>
<Input
value={searchValue} onChange={e => { setSearchValue(e.target.value) }}
style={{ width: 220, marginRight: 15 }} placeholder="数据源或任务名称" />
<Button onClick={() => { queryData() }} type='primary'>查询</Button>
</Row>
<ProTable
columns={columns}
dateFormatter="string"
search={false}
scroll={
{
scrollToFirstRowOnChange: true,
y: clientHeight - 260
}
}
pagination={{
size: 'large',
total: tasks?.count,
showSizeChanger: true,
// showQuickJumper: true,
// current: currentPage,
// pageSize: pageSize || 10,
defaultPageSize: 10,
pageSizeOptions: [10, 20, 50],
// showTotal: (total) => {
// return <span style={{ fontSize: 15 }}>{`共${Math.ceil(total / pageSize)}页,${total}项`}</span>
// },
// onShowSizeChange: (currentPage, pageSize) => {
// setCurrentPage(currentPage);
// setPageSize(pageSize);
// },
// onChange: (page, pageSize) => {
// setCurrentPage(page);
// setPageSize(pageSize);
// }
}}
dataSource={tasks?.rows || []}
options={false}
/>
</Spin>
}
function mapStateToProps(state) {
const {
auth, global, datasources, adapters, tasks
} = state;
return {
loading: datasources.isRequesting || adapters?.isRequesting,
clientHeight: global.clientHeight,
actions: global.actions,
dataSources: datasources?.data || {},
adapters: adapters?.data || [],
tasks: tasks?.data || [],
};
}
export default AcquisitionLog
export default connect(mapStateToProps)(AcquisitionLog);

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

@ -122,9 +122,9 @@ function AcquisitionTask(props) {
{
title: '执行周期',
dataIndex: 'cron',
render: (text, record) => {
return transCron(record?.cron);
}
// render: (text, record) => {
// return transCron(record?.cron);
// }
},
{
title: '重复次数',
@ -143,7 +143,8 @@ function AcquisitionTask(props) {
render: (text, record) => {
const options = [];
options.push(<a onClick={() => {
const param = { id: record.id }
dispatch(actions.metadataAcquisition.runTask(param))
}} style={{ marginRight: 8 }}>立即执行</a>)
const enabledText = record?.enabled ? '禁用' : '启用';
@ -166,7 +167,8 @@ function AcquisitionTask(props) {
<Popconfirm
key="del"
placement="top"
title="是否确认删除该采集任务?"
title={<><div>是否确认删除该采集任务</div>
<div>(将同步删除该任务采集日志)</div></>}
onConfirm={() => handleDelete(record.id)}
okText="是"
cancelText="否"

2
web/client/src/utils/webapi.js

@ -44,7 +44,7 @@ export const ApiTable = {
addTask: 'meta/acq/task',
getTasks: 'meta/acq/tasks',
modifyTask: 'acq/task/{id}',
runTask: 'run/acq/task'
};

Loading…
Cancel
Save