chore: worker added message
This commit is contained in:
@@ -15,7 +15,10 @@ export function useUpdateChunkedList(options: {
|
|||||||
events?: EventsType[];
|
events?: EventsType[];
|
||||||
dataList?: any[];
|
dataList?: any[];
|
||||||
limit?: number;
|
limit?: number;
|
||||||
setDataList: (args: any, opts?: any) => void;
|
onCreate?: (args: any) => void;
|
||||||
|
onUpdate?: (args: any) => void;
|
||||||
|
onDelete?: (args: any) => void;
|
||||||
|
setDataList?: (args: any, opts?: any) => void;
|
||||||
callback?: (args: any) => void;
|
callback?: (args: any) => void;
|
||||||
filterFun?: (args: any) => boolean;
|
filterFun?: (args: any) => boolean;
|
||||||
mapFun?: (args: any) => any;
|
mapFun?: (args: any) => any;
|
||||||
@@ -56,6 +59,7 @@ export function useUpdateChunkedList(options: {
|
|||||||
collections = data?.collection?.map(options?.mapFun);
|
collections = data?.collection?.map(options?.mapFun);
|
||||||
}
|
}
|
||||||
const ids: any[] = data?.ids || [];
|
const ids: any[] = data?.ids || [];
|
||||||
|
|
||||||
// CREATE
|
// CREATE
|
||||||
if (data?.type === WatchEventType.CREATE && events.includes('CREATE')) {
|
if (data?.type === WatchEventType.CREATE && events.includes('CREATE')) {
|
||||||
const newDataList = collections.reduce((acc: any[], item: any) => {
|
const newDataList = collections.reduce((acc: any[], item: any) => {
|
||||||
@@ -71,11 +75,15 @@ export function useUpdateChunkedList(options: {
|
|||||||
|
|
||||||
return acc;
|
return acc;
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
cacheDataListRef.current = [
|
cacheDataListRef.current = [
|
||||||
...newDataList,
|
...newDataList,
|
||||||
...cacheDataListRef.current
|
...cacheDataListRef.current
|
||||||
].slice(0, limit);
|
].slice(0, limit);
|
||||||
|
|
||||||
|
options.onCreate?.(newDataList);
|
||||||
}
|
}
|
||||||
|
|
||||||
// DELETE
|
// DELETE
|
||||||
if (data?.type === WatchEventType.DELETE && events.includes('DELETE')) {
|
if (data?.type === WatchEventType.DELETE && events.includes('DELETE')) {
|
||||||
cacheDataListRef.current = cacheDataListRef.current?.filter(
|
cacheDataListRef.current = cacheDataListRef.current?.filter(
|
||||||
@@ -88,6 +96,7 @@ export function useUpdateChunkedList(options: {
|
|||||||
deletedIds: [...deletedIdsRef.current]
|
deletedIds: [...deletedIdsRef.current]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// UPDATE
|
// UPDATE
|
||||||
if (data?.type === WatchEventType.UPDATE && events.includes('UPDATE')) {
|
if (data?.type === WatchEventType.UPDATE && events.includes('UPDATE')) {
|
||||||
collections?.forEach((item: any) => {
|
collections?.forEach((item: any) => {
|
||||||
@@ -102,6 +111,7 @@ export function useUpdateChunkedList(options: {
|
|||||||
updateItem,
|
updateItem,
|
||||||
...cacheDataListRef.current.slice(0, limit - 1)
|
...cacheDataListRef.current.slice(0, limit - 1)
|
||||||
];
|
];
|
||||||
|
options.onCreate?.([updateItem]);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -88,5 +88,7 @@ Same applies to the <span class="bold-text">/opt/dtk</span> directory.`,
|
|||||||
'clusters.addworker.vendorNotes.title': 'Notes for {vendor} Device',
|
'clusters.addworker.vendorNotes.title': 'Notes for {vendor} Device',
|
||||||
'clusters.button.genToken':
|
'clusters.button.genToken':
|
||||||
'Need to create a new token? Click <a href="{link}" target="_blank">here</a>.',
|
'Need to create a new token? Click <a href="{link}" target="_blank">here</a>.',
|
||||||
'clusters.addworker.amdNotes-01': `If the <span class="bold-text">/opt/rocm</span> directory does not exist, please create a symbolic link pointing to the ROCm installed path: <span class="bold-text">ln -s /path/to/rocm /opt/rocm</span>.`
|
'clusters.addworker.amdNotes-01': `If the <span class="bold-text">/opt/rocm</span> directory does not exist, please create a symbolic link pointing to the ROCm installed path: <span class="bold-text">ln -s /path/to/rocm /opt/rocm</span>.`,
|
||||||
|
'clusters.addworker.message.success':
|
||||||
|
'{count} workers have been added to the cluster.'
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -88,7 +88,9 @@ Same applies to the <span class="bold-text">/opt/dtk</span> directory.`,
|
|||||||
'clusters.addworker.vendorNotes.title': 'Notes for {vendor} Device',
|
'clusters.addworker.vendorNotes.title': 'Notes for {vendor} Device',
|
||||||
'clusters.button.genToken':
|
'clusters.button.genToken':
|
||||||
'Need to create a new token? Click <a href="{link}" target="_blank">here</a>.',
|
'Need to create a new token? Click <a href="{link}" target="_blank">here</a>.',
|
||||||
'clusters.addworker.amdNotes-01': `If the <span class="bold-text">/opt/rocm</span> directory does not exist, please create a symbolic link pointing to the ROCm installed path: <span class="bold-text">ln -s /path/to/rocm /opt/rocm</span>.`
|
'clusters.addworker.amdNotes-01': `If the <span class="bold-text">/opt/rocm</span> directory does not exist, please create a symbolic link pointing to the ROCm installed path: <span class="bold-text">ln -s /path/to/rocm /opt/rocm</span>.`,
|
||||||
|
'clusters.addworker.message.success':
|
||||||
|
'{count} workers have been added to the cluster.'
|
||||||
};
|
};
|
||||||
|
|
||||||
// ========== To-Do: Translate Keys (Remove After Translation) ==========
|
// ========== To-Do: Translate Keys (Remove After Translation) ==========
|
||||||
@@ -165,4 +167,5 @@ Same applies to the <span class="bold-text">/opt/dtk</span> directory.`,
|
|||||||
// 71. 'clusters.addworker.cacheVolume': 'Model Cache Volume Mount',
|
// 71. 'clusters.addworker.cacheVolume': 'Model Cache Volume Mount',
|
||||||
// 72. 'clusters.addworker.cacheVolume.tips': 'If you want to customize the model cache directory, you can specify the path to mount it.',
|
// 72. 'clusters.addworker.cacheVolume.tips': 'If you want to customize the model cache directory, you can specify the path to mount it.',
|
||||||
// 73. 'clusters.addworker.cacheVolume.holder': 'e.g. /data/cache (path must start with /)',
|
// 73. 'clusters.addworker.cacheVolume.holder': 'e.g. /data/cache (path must start with /)',
|
||||||
|
// 74. 'clusters.addworker.message.success': '{count} workers have been added to the cluster.'
|
||||||
// ========== End of To-Do List ==========
|
// ========== End of To-Do List ==========
|
||||||
|
|||||||
@@ -88,7 +88,9 @@ export default {
|
|||||||
'clusters.addworker.vendorNotes.title': 'Примечания для устройств {vendor}',
|
'clusters.addworker.vendorNotes.title': 'Примечания для устройств {vendor}',
|
||||||
'clusters.button.genToken':
|
'clusters.button.genToken':
|
||||||
'Need to create a new token? Click <a href="{link}" target="_blank">here</a>.',
|
'Need to create a new token? Click <a href="{link}" target="_blank">here</a>.',
|
||||||
'clusters.addworker.amdNotes-01': `If the <span class="bold-text">/opt/rocm</span> directory does not exist, please create a symbolic link pointing to the ROCm installed path: <span class="bold-text">ln -s /path/to/rocm /opt/rocm</span>.`
|
'clusters.addworker.amdNotes-01': `If the <span class="bold-text">/opt/rocm</span> directory does not exist, please create a symbolic link pointing to the ROCm installed path: <span class="bold-text">ln -s /path/to/rocm /opt/rocm</span>.`,
|
||||||
|
'clusters.addworker.message.success':
|
||||||
|
'{count} workers have been added to the cluster.'
|
||||||
};
|
};
|
||||||
|
|
||||||
// ========== To-Do: Translate Keys (Remove After Translation) ==========
|
// ========== To-Do: Translate Keys (Remove After Translation) ==========
|
||||||
@@ -96,4 +98,5 @@ export default {
|
|||||||
// 2. 'clusters.button.genToken': 'Need to create a new token? Click <a href="{link}" target="_blank">here</a>.',
|
// 2. 'clusters.button.genToken': 'Need to create a new token? Click <a href="{link}" target="_blank">here</a>.',
|
||||||
// 3. 'clusters.addworker.cacheVolume': 'Model Cache Volume Mount',
|
// 3. 'clusters.addworker.cacheVolume': 'Model Cache Volume Mount',
|
||||||
// 4. 'clusters.addworker.cacheVolume.tips': 'If you want to customize the model cache directory, you can specify the path to mount it.',
|
// 4. 'clusters.addworker.cacheVolume.tips': 'If you want to customize the model cache directory, you can specify the path to mount it.',
|
||||||
|
// 5. 'clusters.addworker.message.success': '{count} workers have been added to the cluster.'
|
||||||
// ================================================================
|
// ================================================================
|
||||||
|
|||||||
@@ -87,5 +87,6 @@ export default {
|
|||||||
'clusters.button.genToken':
|
'clusters.button.genToken':
|
||||||
'需要创建令牌?点击<a href="{link}" target="_blank">这里</a>。',
|
'需要创建令牌?点击<a href="{link}" target="_blank">这里</a>。',
|
||||||
'clusters.addworker.amdNotes-01':
|
'clusters.addworker.amdNotes-01':
|
||||||
'如果 <span class="bold-text">/opt/rocm</span> 目录不存在,请创建一个指向已安装 ROCm 路径的符号链接:<span class="bold-text">ln -s /path/to/rocm /opt/rocm</span>。'
|
'如果 <span class="bold-text">/opt/rocm</span> 目录不存在,请创建一个指向已安装 ROCm 路径的符号链接:<span class="bold-text">ln -s /path/to/rocm /opt/rocm</span>。',
|
||||||
|
'clusters.addworker.message.success': '已将 {count} 个工作节点添加到集群中。'
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import AlertInfoBlock from '@/components/alert-info/block';
|
import AlertInfoBlock from '@/components/alert-info/block';
|
||||||
|
import useAddWorkerMessage from '@/pages/cluster-management/hooks/use-add-worker-message';
|
||||||
import { ExclamationCircleFilled } from '@ant-design/icons';
|
import { ExclamationCircleFilled } from '@ant-design/icons';
|
||||||
import { useIntl } from '@umijs/max';
|
import { useIntl } from '@umijs/max';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
@@ -56,14 +57,21 @@ const AddWorkerSteps: React.FC<AddWorkerProps> = (props) => {
|
|||||||
onClusterChange
|
onClusterChange
|
||||||
} = props || {};
|
} = props || {};
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const { update, summary, register } = useSummaryStatus();
|
|
||||||
|
|
||||||
const [collapseKey, setCollapseKey] = React.useState<Set<string>>(
|
const [collapseKey, setCollapseKey] = React.useState<Set<string>>(
|
||||||
new Set([stepList[0]])
|
new Set([stepList[0]])
|
||||||
);
|
);
|
||||||
|
const startWatchRef = React.useRef(false);
|
||||||
|
const { update, summary, register } = useSummaryStatus();
|
||||||
|
const { contextHolder, createModelsChunkRequest } = useAddWorkerMessage({
|
||||||
|
startWatch: startWatchRef
|
||||||
|
});
|
||||||
|
|
||||||
const onToggle = (open: boolean, key: string) => {
|
const onToggle = (open: boolean, key: string) => {
|
||||||
setCollapseKey(open ? new Set([key]) : new Set());
|
setCollapseKey(open ? new Set([key]) : new Set());
|
||||||
|
if (key === StepNamesMap.RunCommand && open) {
|
||||||
|
startWatchRef.current = true;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleOnClusterChange = (value: number, row?: any) => {
|
const handleOnClusterChange = (value: number, row?: any) => {
|
||||||
@@ -75,6 +83,10 @@ const AddWorkerSteps: React.FC<AddWorkerProps> = (props) => {
|
|||||||
setCollapseKey(new Set([stepList[0]]));
|
setCollapseKey(new Set([stepList[0]]));
|
||||||
}, [stepList]);
|
}, [stepList]);
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
createModelsChunkRequest();
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AddWorkerContext.Provider
|
<AddWorkerContext.Provider
|
||||||
value={{
|
value={{
|
||||||
@@ -128,6 +140,7 @@ const AddWorkerSteps: React.FC<AddWorkerProps> = (props) => {
|
|||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</Container>
|
</Container>
|
||||||
|
{contextHolder}
|
||||||
</AddWorkerContext.Provider>
|
</AddWorkerContext.Provider>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
import useSetChunkRequest from '@/hooks/use-chunk-request';
|
||||||
|
import useUpdateChunkedList from '@/hooks/use-update-chunk-list';
|
||||||
|
import { useIntl } from '@umijs/max';
|
||||||
|
import { message } from 'antd';
|
||||||
|
import _ from 'lodash';
|
||||||
|
import { useRef } from 'react';
|
||||||
|
import { WORKERS_API } from '../../resources/apis';
|
||||||
|
|
||||||
|
export default function useAddWorkerMessage(params: {
|
||||||
|
startWatch?: React.RefObject<boolean>;
|
||||||
|
}) {
|
||||||
|
const chunkRequestRef = useRef<any>(null);
|
||||||
|
const newItemsRef = useRef<any[]>([]);
|
||||||
|
const intl = useIntl();
|
||||||
|
const [messageApi, contextHolder] = message.useMessage();
|
||||||
|
|
||||||
|
const showAddWorkerMessage = _.debounce(() => {
|
||||||
|
if (newItemsRef.current.length > 0) {
|
||||||
|
const count = newItemsRef.current.length;
|
||||||
|
messageApi.success(
|
||||||
|
intl.formatMessage(
|
||||||
|
{ id: 'clusters.addworker.message.success' },
|
||||||
|
{ count }
|
||||||
|
)
|
||||||
|
);
|
||||||
|
newItemsRef.current = [];
|
||||||
|
}
|
||||||
|
}, 300);
|
||||||
|
|
||||||
|
const { setChunkRequest } = useSetChunkRequest();
|
||||||
|
const { updateChunkedList } = useUpdateChunkedList({
|
||||||
|
events: ['CREATE', 'INSERT'],
|
||||||
|
dataList: [],
|
||||||
|
onCreate: (newItems: any) => {
|
||||||
|
if (params.startWatch?.current) {
|
||||||
|
newItemsRef.current = newItemsRef.current.concat(newItems);
|
||||||
|
showAddWorkerMessage();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
const updateHandler = (list: any) => {
|
||||||
|
_.each(list, (data: any) => {
|
||||||
|
updateChunkedList(data);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const createModelsChunkRequest = async () => {
|
||||||
|
chunkRequestRef.current?.current?.cancel?.();
|
||||||
|
try {
|
||||||
|
chunkRequestRef.current = setChunkRequest({
|
||||||
|
url: WORKERS_API,
|
||||||
|
handler: updateHandler
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
contextHolder,
|
||||||
|
createModelsChunkRequest
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -48,6 +48,7 @@ const Workers: React.FC = () => {
|
|||||||
} = useTableFetch<ListItem>({
|
} = useTableFetch<ListItem>({
|
||||||
fetchAPI: queryWorkersList,
|
fetchAPI: queryWorkersList,
|
||||||
deleteAPI: deleteWorker,
|
deleteAPI: deleteWorker,
|
||||||
|
events: ['UPDATE', 'DELETE', 'INSERT'],
|
||||||
contentForDelete: 'resources.worker',
|
contentForDelete: 'resources.worker',
|
||||||
watch: true,
|
watch: true,
|
||||||
API: WORKERS_API
|
API: WORKERS_API
|
||||||
|
|||||||
Reference in New Issue
Block a user