fix: add worker message trigger
This commit is contained in:
@@ -61,7 +61,6 @@ const useSetChunkRequest = () => {
|
|||||||
const timer = useRef<any>(null);
|
const timer = useRef<any>(null);
|
||||||
const loadedSize = useRef(0);
|
const loadedSize = useRef(0);
|
||||||
const workerRef = useRef<any>(null);
|
const workerRef = useRef<any>(null);
|
||||||
const startLoadingRef = useRef(false);
|
|
||||||
|
|
||||||
const reset = () => {
|
const reset = () => {
|
||||||
loaded.current = 0;
|
loaded.current = 0;
|
||||||
@@ -170,7 +169,6 @@ const useSetChunkRequest = () => {
|
|||||||
const setChunkRequest = (config: RequestConfig) => {
|
const setChunkRequest = (config: RequestConfig) => {
|
||||||
requestConfig.current = { ...particalConfig, ...config };
|
requestConfig.current = { ...particalConfig, ...config };
|
||||||
retryCount.current = totalCount;
|
retryCount.current = totalCount;
|
||||||
startLoadingRef.current = false;
|
|
||||||
clearTimeout(timer.current);
|
clearTimeout(timer.current);
|
||||||
axiosChunkRequest(requestConfig.current);
|
axiosChunkRequest(requestConfig.current);
|
||||||
return axiosToken;
|
return axiosToken;
|
||||||
@@ -203,17 +201,11 @@ const useSetChunkRequest = () => {
|
|||||||
2 ** (totalCount - retryCount.current) * 1000
|
2 ** (totalCount - retryCount.current) * 1000
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (requestReadyState === 3) {
|
|
||||||
setTimeout(() => {
|
|
||||||
startLoadingRef.current = true;
|
|
||||||
}, 5000);
|
|
||||||
}
|
|
||||||
}, [requestReadyState]);
|
}, [requestReadyState]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
setChunkRequest,
|
setChunkRequest,
|
||||||
createAxiosToken,
|
createAxiosToken
|
||||||
startLoadingRef
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ type EventsType = 'CREATE' | 'UPDATE' | 'DELETE' | 'INSERT';
|
|||||||
export function useUpdateChunkedList(options: {
|
export function useUpdateChunkedList(options: {
|
||||||
events?: EventsType[];
|
events?: EventsType[];
|
||||||
dataList?: any[];
|
dataList?: any[];
|
||||||
|
triggerAt?: React.MutableRefObject<number>;
|
||||||
limit?: number;
|
limit?: number;
|
||||||
onCreate?: (args: any) => void;
|
onCreate?: (args: any) => void;
|
||||||
onUpdate?: (args: any) => void;
|
onUpdate?: (args: any) => void;
|
||||||
@@ -24,7 +25,8 @@ export function useUpdateChunkedList(options: {
|
|||||||
mapFun?: (args: any) => any;
|
mapFun?: (args: any) => any;
|
||||||
computedID?: (d: object) => string;
|
computedID?: (d: object) => string;
|
||||||
}) {
|
}) {
|
||||||
const { events = ['CREATE', 'DELETE', 'UPDATE', 'INSERT'] } = options;
|
const { events = ['CREATE', 'DELETE', 'UPDATE', 'INSERT'], triggerAt } =
|
||||||
|
options;
|
||||||
const deletedIdsRef = useRef<Set<number | string>>(new Set());
|
const deletedIdsRef = useRef<Set<number | string>>(new Set());
|
||||||
const cacheDataListRef = useRef<any[]>(options.dataList || []);
|
const cacheDataListRef = useRef<any[]>(options.dataList || []);
|
||||||
const timerRef = useRef<any>(null);
|
const timerRef = useRef<any>(null);
|
||||||
@@ -63,6 +65,7 @@ export function useUpdateChunkedList(options: {
|
|||||||
|
|
||||||
// CREATE
|
// CREATE
|
||||||
if (data?.type === WatchEventType.CREATE && events.includes('CREATE')) {
|
if (data?.type === WatchEventType.CREATE && events.includes('CREATE')) {
|
||||||
|
const latestCreateList: any[] = [];
|
||||||
const newDataList = collections.reduce((acc: any[], item: any) => {
|
const newDataList = collections.reduce((acc: any[], item: any) => {
|
||||||
const updateIndex = cacheDataListRef.current?.findIndex(
|
const updateIndex = cacheDataListRef.current?.findIndex(
|
||||||
(sItem: any) => sItem.id === item.id
|
(sItem: any) => sItem.id === item.id
|
||||||
@@ -73,6 +76,12 @@ export function useUpdateChunkedList(options: {
|
|||||||
} else {
|
} else {
|
||||||
cacheDataListRef.current[updateIndex] = updateItem;
|
cacheDataListRef.current[updateIndex] = updateItem;
|
||||||
}
|
}
|
||||||
|
if (
|
||||||
|
triggerAt?.current &&
|
||||||
|
Date.parse(item.created_at) >= triggerAt.current
|
||||||
|
) {
|
||||||
|
latestCreateList.push(updateItem);
|
||||||
|
}
|
||||||
|
|
||||||
return acc;
|
return acc;
|
||||||
}, []);
|
}, []);
|
||||||
@@ -82,7 +91,7 @@ export function useUpdateChunkedList(options: {
|
|||||||
...cacheDataListRef.current
|
...cacheDataListRef.current
|
||||||
].slice(0, limit);
|
].slice(0, limit);
|
||||||
|
|
||||||
options.onCreate?.(newDataList);
|
options.onCreate?.(latestCreateList);
|
||||||
}
|
}
|
||||||
|
|
||||||
// DELETE
|
// DELETE
|
||||||
@@ -112,7 +121,11 @@ export function useUpdateChunkedList(options: {
|
|||||||
updateItem,
|
updateItem,
|
||||||
...cacheDataListRef.current.slice(0, limit - 1)
|
...cacheDataListRef.current.slice(0, limit - 1)
|
||||||
];
|
];
|
||||||
options.onCreate?.([updateItem]);
|
if (options.onCreate && triggerAt?.current) {
|
||||||
|
if (Date.parse(item.created_at) >= triggerAt.current) {
|
||||||
|
options.onCreate?.([updateItem]);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -370,7 +370,7 @@ const VersionsForm: React.FC<AddModalProps> = ({
|
|||||||
{ id: 'common.help.eg' },
|
{ id: 'common.help.eg' },
|
||||||
{
|
{
|
||||||
content:
|
content:
|
||||||
'vllm serve {{model_path}} --port {{port}} --host {{worker_ip}} --served-model-name {{model_name}}'
|
'{{model_path}} --port {{port}} --host {{worker_ip}} --served-model-name {{model_name}}'
|
||||||
}
|
}
|
||||||
)}
|
)}
|
||||||
label={intl.formatMessage({ id: 'backend.runCommand' })}
|
label={intl.formatMessage({ id: 'backend.runCommand' })}
|
||||||
|
|||||||
@@ -60,8 +60,7 @@ const AddWorker: React.FC<AddWorkerProps> = (props) => {
|
|||||||
stepList = []
|
stepList = []
|
||||||
} = props || {};
|
} = props || {};
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const { addedCount, createModelsChunkRequest, chunkRequestRef } =
|
const { addedCount, createModelsChunkRequest, reset } = useAddWorkerMessage();
|
||||||
useAddWorkerMessage();
|
|
||||||
const firstLoad = React.useRef(true);
|
const firstLoad = React.useRef(true);
|
||||||
const axiosTokenRef = React.useRef<any>(null);
|
const axiosTokenRef = React.useRef<any>(null);
|
||||||
const [registrationInfo, setRegistrationInfo] = React.useState<{
|
const [registrationInfo, setRegistrationInfo] = React.useState<{
|
||||||
@@ -100,8 +99,8 @@ const AddWorker: React.FC<AddWorkerProps> = (props) => {
|
|||||||
}
|
}
|
||||||
return () => {
|
return () => {
|
||||||
firstLoad.current = true;
|
firstLoad.current = true;
|
||||||
chunkRequestRef.current?.current?.cancel?.();
|
|
||||||
axiosTokenRef.current?.cancel?.();
|
axiosTokenRef.current?.cancel?.();
|
||||||
|
reset();
|
||||||
};
|
};
|
||||||
}, [open, cluster_id]);
|
}, [open, cluster_id]);
|
||||||
|
|
||||||
@@ -109,7 +108,7 @@ const AddWorker: React.FC<AddWorkerProps> = (props) => {
|
|||||||
if (open) {
|
if (open) {
|
||||||
createModelsChunkRequest();
|
createModelsChunkRequest();
|
||||||
} else {
|
} else {
|
||||||
chunkRequestRef.current?.current?.cancel?.();
|
reset();
|
||||||
axiosTokenRef.current?.cancel?.();
|
axiosTokenRef.current?.cancel?.();
|
||||||
}
|
}
|
||||||
}, [open]);
|
}, [open]);
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ export default function useAddWorkerMessage() {
|
|||||||
const newItemsRef = useRef<any[]>([]);
|
const newItemsRef = useRef<any[]>([]);
|
||||||
const [addedCount, setAddedCount] = useState(0);
|
const [addedCount, setAddedCount] = useState(0);
|
||||||
const timerRef = useRef<any>(null);
|
const timerRef = useRef<any>(null);
|
||||||
|
const triggerAtRef = useRef<number>(0);
|
||||||
|
|
||||||
const showAddWorkerMessage = () => {
|
const showAddWorkerMessage = () => {
|
||||||
if (newItemsRef.current.length > 0) {
|
if (newItemsRef.current.length > 0) {
|
||||||
@@ -17,12 +18,13 @@ export default function useAddWorkerMessage() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const { setChunkRequest, startLoadingRef } = useSetChunkRequest();
|
const { setChunkRequest } = useSetChunkRequest();
|
||||||
const { updateChunkedList } = useUpdateChunkedList({
|
const { updateChunkedList } = useUpdateChunkedList({
|
||||||
events: ['CREATE', 'INSERT'],
|
events: ['CREATE', 'INSERT'],
|
||||||
dataList: [],
|
dataList: [],
|
||||||
|
triggerAt: triggerAtRef,
|
||||||
onCreate: (newItems: any) => {
|
onCreate: (newItems: any) => {
|
||||||
if (startLoadingRef.current) {
|
if (triggerAtRef.current) {
|
||||||
newItemsRef.current = newItemsRef.current.concat(newItems);
|
newItemsRef.current = newItemsRef.current.concat(newItems);
|
||||||
showAddWorkerMessage();
|
showAddWorkerMessage();
|
||||||
}
|
}
|
||||||
@@ -37,18 +39,20 @@ export default function useAddWorkerMessage() {
|
|||||||
|
|
||||||
const resetAddedCount = () => {
|
const resetAddedCount = () => {
|
||||||
setAddedCount(0);
|
setAddedCount(0);
|
||||||
|
chunkRequestRef.current?.current?.cancel?.();
|
||||||
newItemsRef.current = [];
|
newItemsRef.current = [];
|
||||||
|
triggerAtRef.current = 0;
|
||||||
clearTimeout(timerRef.current);
|
clearTimeout(timerRef.current);
|
||||||
};
|
};
|
||||||
|
|
||||||
const createModelsChunkRequest = async () => {
|
const createModelsChunkRequest = async () => {
|
||||||
chunkRequestRef.current?.current?.cancel?.();
|
|
||||||
resetAddedCount();
|
resetAddedCount();
|
||||||
try {
|
try {
|
||||||
chunkRequestRef.current = setChunkRequest({
|
chunkRequestRef.current = setChunkRequest({
|
||||||
url: WORKERS_API,
|
url: WORKERS_API,
|
||||||
handler: updateHandler
|
handler: updateHandler
|
||||||
});
|
});
|
||||||
|
triggerAtRef.current = Date.now();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
@@ -56,15 +60,14 @@ export default function useAddWorkerMessage() {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
return () => {
|
return () => {
|
||||||
chunkRequestRef.current?.current?.cancel?.();
|
resetAddedCount();
|
||||||
newItemsRef.current = [];
|
|
||||||
clearTimeout(timerRef.current);
|
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
addedCount,
|
addedCount,
|
||||||
chunkRequestRef,
|
chunkRequestRef,
|
||||||
|
reset: resetAddedCount,
|
||||||
createModelsChunkRequest
|
createModelsChunkRequest
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user