mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-22 22:36:06 +08:00
修复任务详情日志列表卡顿
This commit is contained in:
parent
6832cb4e22
commit
39bfd39559
|
@ -21,7 +21,7 @@ export class Crontab {
|
||||||
|
|
||||||
constructor(options: Crontab) {
|
constructor(options: Crontab) {
|
||||||
this.name = options.name;
|
this.name = options.name;
|
||||||
this.command = options.command;
|
this.command = options.command.trim();
|
||||||
this.schedule = options.schedule;
|
this.schedule = options.schedule;
|
||||||
this.saved = options.saved;
|
this.saved = options.saved;
|
||||||
this.id = options.id;
|
this.id = options.id;
|
||||||
|
|
|
@ -17,7 +17,7 @@ const addCron = (
|
||||||
scheduleStacks.get(id)?.cancel();
|
scheduleStacks.get(id)?.cancel();
|
||||||
}
|
}
|
||||||
|
|
||||||
let cmdStr = command;
|
let cmdStr = command.trim();
|
||||||
if (!cmdStr.startsWith(TASK_PREFIX) && !cmdStr.startsWith(QL_PREFIX)) {
|
if (!cmdStr.startsWith(TASK_PREFIX) && !cmdStr.startsWith(QL_PREFIX)) {
|
||||||
cmdStr = `${TASK_PREFIX}${cmdStr}`;
|
cmdStr = `${TASK_PREFIX}${cmdStr}`;
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,12 @@ const addCron = (
|
||||||
scheduleStacks.set(
|
scheduleStacks.set(
|
||||||
id,
|
id,
|
||||||
nodeSchedule.scheduleJob(id, schedule, async () => {
|
nodeSchedule.scheduleJob(id, schedule, async () => {
|
||||||
Logger.silly(`当前时间: ${dayjs().format('YYYY-MM-DD HH:mm:ss')},运行命令: ${cmdStr}`);
|
Logger.info(
|
||||||
runCron(`ID=${id} ${cmdStr}`)
|
`当前时间: ${dayjs().format(
|
||||||
|
'YYYY-MM-DD HH:mm:ss',
|
||||||
|
)},运行命令: ${cmdStr}`,
|
||||||
|
);
|
||||||
|
runCron(`ID=${id} ${cmdStr}`);
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -507,13 +507,14 @@ export default class CronService {
|
||||||
}
|
}
|
||||||
|
|
||||||
private make_command(tab: Crontab) {
|
private make_command(tab: Crontab) {
|
||||||
|
let command = tab.command.trim();
|
||||||
if (
|
if (
|
||||||
!tab.command.startsWith(TASK_PREFIX) &&
|
!command.startsWith(TASK_PREFIX) &&
|
||||||
!tab.command.startsWith(QL_PREFIX)
|
!command.startsWith(QL_PREFIX)
|
||||||
) {
|
) {
|
||||||
tab.command = `${TASK_PREFIX}${tab.command}`;
|
command = `${TASK_PREFIX}${tab.command}`;
|
||||||
}
|
}
|
||||||
const crontab_job_string = `ID=${tab.id} ${tab.command}`;
|
const crontab_job_string = `ID=${tab.id} ${command}`;
|
||||||
return crontab_job_string;
|
return crontab_job_string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ class TaskLimit {
|
||||||
this.cpuLimit = pLimit(limit);
|
this.cpuLimit = pLimit(limit);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
await AuthModel.sync();
|
||||||
const doc = await AuthModel.findOne({ where: { type: AuthDataType.systemConfig } });
|
const doc = await AuthModel.findOne({ where: { type: AuthDataType.systemConfig } });
|
||||||
if (doc?.info?.cronConcurrency) {
|
if (doc?.info?.cronConcurrency) {
|
||||||
this.cpuLimit = pLimit(doc?.info?.cronConcurrency);
|
this.cpuLimit = pLimit(doc?.info?.cronConcurrency);
|
||||||
|
|
|
@ -145,6 +145,7 @@
|
||||||
"qrcode.react": "^1.0.1",
|
"qrcode.react": "^1.0.1",
|
||||||
"query-string": "^7.1.1",
|
"query-string": "^7.1.1",
|
||||||
"rc-tween-one": "^3.0.6",
|
"rc-tween-one": "^3.0.6",
|
||||||
|
"rc-virtual-list": "3.5.3",
|
||||||
"react": "18.2.0",
|
"react": "18.2.0",
|
||||||
"react-codemirror2": "^7.2.1",
|
"react-codemirror2": "^7.2.1",
|
||||||
"react-copy-to-clipboard": "^5.1.0",
|
"react-copy-to-clipboard": "^5.1.0",
|
||||||
|
|
|
@ -267,6 +267,9 @@ devDependencies:
|
||||||
rc-tween-one:
|
rc-tween-one:
|
||||||
specifier: ^3.0.6
|
specifier: ^3.0.6
|
||||||
version: 3.0.6(react-dom@18.2.0)(react@18.2.0)
|
version: 3.0.6(react-dom@18.2.0)(react@18.2.0)
|
||||||
|
rc-virtual-list:
|
||||||
|
specifier: 3.5.3
|
||||||
|
version: 3.5.3(react-dom@18.2.0)(react@18.2.0)
|
||||||
react:
|
react:
|
||||||
specifier: 18.2.0
|
specifier: 18.2.0
|
||||||
version: 18.2.0
|
version: 18.2.0
|
||||||
|
@ -12461,7 +12464,7 @@ packages:
|
||||||
rc-overflow: 1.3.0(react-dom@18.2.0)(react@18.2.0)
|
rc-overflow: 1.3.0(react-dom@18.2.0)(react@18.2.0)
|
||||||
rc-trigger: 5.3.4(react-dom@18.2.0)(react@18.2.0)
|
rc-trigger: 5.3.4(react-dom@18.2.0)(react@18.2.0)
|
||||||
rc-util: 5.33.0(react-dom@18.2.0)(react@18.2.0)
|
rc-util: 5.33.0(react-dom@18.2.0)(react@18.2.0)
|
||||||
rc-virtual-list: 3.5.2(react-dom@18.2.0)(react@18.2.0)
|
rc-virtual-list: 3.5.3(react-dom@18.2.0)(react@18.2.0)
|
||||||
react: 18.2.0
|
react: 18.2.0
|
||||||
react-dom: 18.2.0(react@18.2.0)
|
react-dom: 18.2.0(react@18.2.0)
|
||||||
dev: true
|
dev: true
|
||||||
|
@ -12641,7 +12644,7 @@ packages:
|
||||||
classnames: 2.3.2
|
classnames: 2.3.2
|
||||||
rc-motion: 2.7.3(react-dom@18.2.0)(react@18.2.0)
|
rc-motion: 2.7.3(react-dom@18.2.0)(react@18.2.0)
|
||||||
rc-util: 5.33.0(react-dom@18.2.0)(react@18.2.0)
|
rc-util: 5.33.0(react-dom@18.2.0)(react@18.2.0)
|
||||||
rc-virtual-list: 3.5.2(react-dom@18.2.0)(react@18.2.0)
|
rc-virtual-list: 3.5.3(react-dom@18.2.0)(react@18.2.0)
|
||||||
react: 18.2.0
|
react: 18.2.0
|
||||||
react-dom: 18.2.0(react@18.2.0)
|
react-dom: 18.2.0(react@18.2.0)
|
||||||
dev: true
|
dev: true
|
||||||
|
@ -12731,8 +12734,8 @@ packages:
|
||||||
react-is: 16.13.1
|
react-is: 16.13.1
|
||||||
dev: true
|
dev: true
|
||||||
|
|
||||||
/rc-virtual-list@3.5.2(react-dom@18.2.0)(react@18.2.0):
|
/rc-virtual-list@3.5.3(react-dom@18.2.0)(react@18.2.0):
|
||||||
resolution: {integrity: sha512-sE2G9hTPjVmatQni8OP2Kx33+Oth6DMKm67OblBBmgMBJDJQOOFpSGH7KZ6Pm85rrI2IGxDRXZCr0QhYOH2pfQ==}
|
resolution: {integrity: sha512-rG6IuD4EYM8K6oZ8Shu2BC/CmcTdqng4yBWkc/5fjWhB20bl6QwR2Upyt7+MxvfscoVm8zOQY+tcpEO5cu4GaQ==}
|
||||||
engines: {node: '>=8.x'}
|
engines: {node: '>=8.x'}
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
react: '*'
|
react: '*'
|
||||||
|
|
14
src/hooks/useScrollHeight.ts
Normal file
14
src/hooks/useScrollHeight.ts
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
import { RefObject, useState } from 'react';
|
||||||
|
import useResizeObserver from '@react-hook/resize-observer';
|
||||||
|
|
||||||
|
export default <T extends HTMLElement>(target: RefObject<T>) => {
|
||||||
|
const [height, setHeight] = useState<number>(0);
|
||||||
|
|
||||||
|
useResizeObserver(target, (entry) => {
|
||||||
|
let _height = entry.target.clientHeight;
|
||||||
|
if (height !== _height) {
|
||||||
|
setHeight(_height);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return height;
|
||||||
|
};
|
|
@ -1,9 +1,9 @@
|
||||||
import { MutableRefObject, useLayoutEffect, useState } from 'react';
|
import { RefObject, useState } from 'react';
|
||||||
import useResizeObserver from '@react-hook/resize-observer';
|
import useResizeObserver from '@react-hook/resize-observer';
|
||||||
import { getTableScroll } from '@/utils';
|
import { getTableScroll } from '@/utils';
|
||||||
|
|
||||||
export default <T extends HTMLElement>(
|
export default <T extends HTMLElement>(
|
||||||
target: MutableRefObject<T>,
|
target: RefObject<T>,
|
||||||
extraHeight?: number,
|
extraHeight?: number,
|
||||||
) => {
|
) => {
|
||||||
const [height, setHeight] = useState<number>(0);
|
const [height, setHeight] = useState<number>(0);
|
||||||
|
|
|
@ -30,6 +30,8 @@ import CronLogModal from './logModal';
|
||||||
import Editor from '@monaco-editor/react';
|
import Editor from '@monaco-editor/react';
|
||||||
import IconFont from '@/components/iconfont';
|
import IconFont from '@/components/iconfont';
|
||||||
import { getCommandScript } from '@/utils';
|
import { getCommandScript } from '@/utils';
|
||||||
|
import VirtualList from 'rc-virtual-list';
|
||||||
|
import useScrollHeight from '@/hooks/useScrollHeight';
|
||||||
|
|
||||||
const { Text } = Typography;
|
const { Text } = Typography;
|
||||||
|
|
||||||
|
@ -81,19 +83,28 @@ const CronDetailModal = ({
|
||||||
const [logUrl, setLogUrl] = useState('');
|
const [logUrl, setLogUrl] = useState('');
|
||||||
const [validTabs, setValidTabs] = useState(tabList);
|
const [validTabs, setValidTabs] = useState(tabList);
|
||||||
const [currentCron, setCurrentCron] = useState<any>({});
|
const [currentCron, setCurrentCron] = useState<any>({});
|
||||||
|
const listRef = useRef<HTMLDivElement>(null);
|
||||||
|
const tableScrollHeight = useScrollHeight(listRef);
|
||||||
|
|
||||||
const contentList: any = {
|
const contentList: any = {
|
||||||
log: (
|
log: (
|
||||||
<List
|
<div ref={listRef}>
|
||||||
dataSource={logs}
|
<List>
|
||||||
loading={loading}
|
<VirtualList
|
||||||
renderItem={(item) => (
|
data={logs}
|
||||||
<List.Item className="log-item" onClick={() => onClickItem(item)}>
|
height={tableScrollHeight}
|
||||||
<FileOutlined style={{ marginRight: 10 }} />
|
itemHeight={47}
|
||||||
{item.directory}/{item.filename}
|
itemKey="filename"
|
||||||
</List.Item>
|
>
|
||||||
)}
|
{(item) => (
|
||||||
/>
|
<List.Item className="log-item" onClick={() => onClickItem(item)}>
|
||||||
|
<FileOutlined style={{ marginRight: 10 }} />
|
||||||
|
{item.directory}/{item.filename}
|
||||||
|
</List.Item>
|
||||||
|
)}
|
||||||
|
</VirtualList>
|
||||||
|
</List>
|
||||||
|
</div>
|
||||||
),
|
),
|
||||||
script: scriptInfo.filename && (
|
script: scriptInfo.filename && (
|
||||||
<Editor
|
<Editor
|
||||||
|
@ -248,7 +259,7 @@ const CronDetailModal = ({
|
||||||
),
|
),
|
||||||
onOk() {
|
onOk() {
|
||||||
request
|
request
|
||||||
.put(`${config.apiPrefix}crons/stop`, [currentCron.id] )
|
.put(`${config.apiPrefix}crons/stop`, [currentCron.id])
|
||||||
.then(({ code, data }) => {
|
.then(({ code, data }) => {
|
||||||
if (code === 200) {
|
if (code === 200) {
|
||||||
setCurrentCron({ ...currentCron, status: CrontabStatus.idle });
|
setCurrentCron({ ...currentCron, status: CrontabStatus.idle });
|
||||||
|
@ -280,7 +291,7 @@ const CronDetailModal = ({
|
||||||
`${config.apiPrefix}crons/${
|
`${config.apiPrefix}crons/${
|
||||||
currentCron.isDisabled === 1 ? 'enable' : 'disable'
|
currentCron.isDisabled === 1 ? 'enable' : 'disable'
|
||||||
}`,
|
}`,
|
||||||
[currentCron.id],
|
[currentCron.id],
|
||||||
)
|
)
|
||||||
.then(({ code, data }) => {
|
.then(({ code, data }) => {
|
||||||
if (code === 200) {
|
if (code === 200) {
|
||||||
|
|
|
@ -10,6 +10,10 @@
|
||||||
height: calc(90vh - 367px);
|
height: calc(90vh - 367px);
|
||||||
height: calc(90vh - var(--vh-offset, 0px) - 367px);
|
height: calc(90vh - var(--vh-offset, 0px) - 367px);
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
|
|
||||||
|
> div {
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -347,7 +347,7 @@ const Crontab = () => {
|
||||||
const [cronViews, setCronViews] = useState<any[]>([]);
|
const [cronViews, setCronViews] = useState<any[]>([]);
|
||||||
const [enabledCronViews, setEnabledCronViews] = useState<any[]>([]);
|
const [enabledCronViews, setEnabledCronViews] = useState<any[]>([]);
|
||||||
const [moreMenuActive, setMoreMenuActive] = useState(false);
|
const [moreMenuActive, setMoreMenuActive] = useState(false);
|
||||||
const tableRef = useRef<any>();
|
const tableRef = useRef<HTMLDivElement>(null);
|
||||||
const tableScrollHeight = useTableScrollHeight(tableRef);
|
const tableScrollHeight = useTableScrollHeight(tableRef);
|
||||||
|
|
||||||
const goToScriptManager = (record: any) => {
|
const goToScriptManager = (record: any) => {
|
||||||
|
|
|
@ -31,7 +31,7 @@ const CronModal = ({
|
||||||
);
|
);
|
||||||
|
|
||||||
if (code === 200) {
|
if (code === 200) {
|
||||||
message.success(cron ? '更新Cron成功' : '新建Cron成功');
|
message.success(cron ? '更新任务成功' : '新建任务成功');
|
||||||
handleCancel(data);
|
handleCancel(data);
|
||||||
}
|
}
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
|
|
|
@ -190,7 +190,7 @@ const Dependence = () => {
|
||||||
const [logDependence, setLogDependence] = useState<any>();
|
const [logDependence, setLogDependence] = useState<any>();
|
||||||
const [isLogModalVisible, setIsLogModalVisible] = useState(false);
|
const [isLogModalVisible, setIsLogModalVisible] = useState(false);
|
||||||
const [type, setType] = useState('nodejs');
|
const [type, setType] = useState('nodejs');
|
||||||
const tableRef = useRef<any>();
|
const tableRef = useRef<HTMLDivElement>(null);
|
||||||
const tableScrollHeight = useTableScrollHeight(tableRef, 59);
|
const tableScrollHeight = useTableScrollHeight(tableRef, 59);
|
||||||
|
|
||||||
const getDependencies = () => {
|
const getDependencies = () => {
|
||||||
|
|
2
src/pages/env/index.tsx
vendored
2
src/pages/env/index.tsx
vendored
|
@ -214,7 +214,7 @@ const Env = () => {
|
||||||
const [selectedRowIds, setSelectedRowIds] = useState<string[]>([]);
|
const [selectedRowIds, setSelectedRowIds] = useState<string[]>([]);
|
||||||
const [searchText, setSearchText] = useState('');
|
const [searchText, setSearchText] = useState('');
|
||||||
const [importLoading, setImportLoading] = useState(false);
|
const [importLoading, setImportLoading] = useState(false);
|
||||||
const tableRef = useRef<any>();
|
const tableRef = useRef<HTMLDivElement>(null);
|
||||||
const tableScrollHeight = useTableScrollHeight(tableRef, 59);
|
const tableScrollHeight = useTableScrollHeight(tableRef, 59);
|
||||||
|
|
||||||
const getEnvs = () => {
|
const getEnvs = () => {
|
||||||
|
|
|
@ -207,7 +207,7 @@ const Other = ({
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item label="数据备份还原" name="frequency">
|
<Form.Item label="数据备份还原" name="frequency">
|
||||||
<Button type="primary" onClick={exportData} loading={exportLoading}>
|
<Button type="primary" onClick={exportData} loading={exportLoading}>
|
||||||
备份
|
{exportLoading ? '生成数据中...' : '备份'}
|
||||||
</Button>
|
</Button>
|
||||||
<Upload
|
<Upload
|
||||||
method="put"
|
method="put"
|
||||||
|
|
|
@ -237,7 +237,7 @@ const Subscription = () => {
|
||||||
const [pageSize, setPageSize] = useState(20);
|
const [pageSize, setPageSize] = useState(20);
|
||||||
const [isLogModalVisible, setIsLogModalVisible] = useState(false);
|
const [isLogModalVisible, setIsLogModalVisible] = useState(false);
|
||||||
const [logSubscription, setLogSubscription] = useState<any>();
|
const [logSubscription, setLogSubscription] = useState<any>();
|
||||||
const tableRef = useRef<any>();
|
const tableRef = useRef<HTMLDivElement>(null);
|
||||||
const tableScrollHeight = useTableScrollHeight(tableRef);
|
const tableScrollHeight = useTableScrollHeight(tableRef);
|
||||||
|
|
||||||
const runSubscription = (record: any, index: number) => {
|
const runSubscription = (record: any, index: number) => {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user