fix(models): cancel model-route-targets watch on inactive tab
This commit is contained in:
@@ -40,6 +40,11 @@ export default function useWatchList<T = Record<string, any>>(API: string) {
|
||||
}
|
||||
});
|
||||
|
||||
const cancelWatch = useMemoizedFn(() => {
|
||||
chunkRequestRef.current?.current?.cancel?.();
|
||||
listRequestTokenRef.current?.cancel?.();
|
||||
});
|
||||
|
||||
const queryAllDataList = async (
|
||||
params: Global.SearchParams,
|
||||
options?: any
|
||||
@@ -78,14 +83,15 @@ export default function useWatchList<T = Record<string, any>>(API: string) {
|
||||
useEffect(() => {
|
||||
createWatchChunkRequest();
|
||||
return () => {
|
||||
chunkRequestRef.current?.cancel?.();
|
||||
listRequestTokenRef.current?.cancel?.();
|
||||
cancelWatch();
|
||||
};
|
||||
}, []);
|
||||
|
||||
return {
|
||||
watchDataList,
|
||||
setWatchDataList,
|
||||
startWatch: createWatchChunkRequest,
|
||||
cancelWatch,
|
||||
deleteItemFromCache: handleDeleteItemFromCache
|
||||
};
|
||||
}
|
||||
|
||||
@@ -5,9 +5,7 @@ import { PageActionType } from '@/config/types';
|
||||
import useBodyScroll from '@/hooks/use-body-scroll';
|
||||
import useExpandedRowKeys from '@/hooks/use-expanded-row-keys';
|
||||
import useTableRowSelection from '@/hooks/use-table-row-selection';
|
||||
import useWatchList from '@/hooks/use-watch-list';
|
||||
import useNoResourceResult from '@/pages/llmodels/hooks/use-no-resource-result';
|
||||
import { MODEL_ROUTE_TARGETS } from '@/pages/model-routes/apis';
|
||||
import { TargetStatusValueMap } from '@/pages/model-routes/config';
|
||||
import useOpenPlayground from '@/pages/model-routes/hooks/use-open-playground';
|
||||
import useGranfanaLink from '@/pages/resources/hooks/use-grafana-link';
|
||||
@@ -92,6 +90,7 @@ interface ModelsProps {
|
||||
loadend: boolean;
|
||||
total: number;
|
||||
filterValues?: Record<string, any>;
|
||||
targetList?: any[];
|
||||
}
|
||||
|
||||
const getFormattedData = (record: any, extraData = {}) => ({
|
||||
@@ -129,7 +128,8 @@ const Models: React.FC<ModelsProps> = ({
|
||||
queryParams,
|
||||
loading,
|
||||
loadend,
|
||||
total
|
||||
total,
|
||||
targetList = []
|
||||
}) => {
|
||||
const { generateFormValues, clusterList, workerList } =
|
||||
useDeploymentsContext();
|
||||
@@ -155,7 +155,6 @@ const Models: React.FC<ModelsProps> = ({
|
||||
expandedRowKeys
|
||||
} = useExpandedRowKeys(expandAtom);
|
||||
const { handleOpenPlayGround } = useOpenPlayground();
|
||||
const { watchDataList: targetList } = useWatchList(MODEL_ROUTE_TARGETS);
|
||||
const { openViewLogsModal, openViewLogsModalStatus, closeViewLogsModal } =
|
||||
useViewInstanceLogs();
|
||||
|
||||
|
||||
@@ -3,6 +3,8 @@ import useSetChunkRequest from '@/hooks/use-chunk-request';
|
||||
import { usePaginationStatus } from '@/hooks/use-pagination-status';
|
||||
import { useTableMultiSort } from '@/hooks/use-table-sort';
|
||||
import useUpdateChunkedList from '@/hooks/use-update-chunk-list';
|
||||
import useWatchList from '@/hooks/use-watch-list';
|
||||
import { MODEL_ROUTE_TARGETS } from '@/pages/model-routes/apis';
|
||||
import { TableOrder, TableProvider } from '@gpustack/core-ui';
|
||||
import { useMemoizedFn } from 'ahooks';
|
||||
import _ from 'lodash';
|
||||
@@ -31,6 +33,11 @@ const Models = forwardRef((props, ref) => {
|
||||
const { setChunkRequest, createAxiosToken } = useSetChunkRequest();
|
||||
const { setChunkRequest: setModelInstanceChunkRequest } =
|
||||
useSetChunkRequest();
|
||||
const {
|
||||
watchDataList: targetList,
|
||||
startWatch: startTargetsWatch,
|
||||
cancelWatch: cancelTargetsWatch
|
||||
} = useWatchList(MODEL_ROUTE_TARGETS);
|
||||
const [modelInstances, setModelInstances] = useState<any[]>([]);
|
||||
const [dataSource, setDataSource] = useState<{
|
||||
dataList: ListItem[];
|
||||
@@ -255,6 +262,7 @@ const Models = forwardRef((props, ref) => {
|
||||
cacheInsDataListRef.current = [];
|
||||
chunkInstanceRequedtRef.current?.current?.cancel?.();
|
||||
instancesToken.current?.cancel?.();
|
||||
cancelTargetsWatch();
|
||||
});
|
||||
|
||||
const resumeRequestsOnPageActive = useMemoizedFn(async () => {
|
||||
@@ -265,6 +273,7 @@ const Models = forwardRef((props, ref) => {
|
||||
await getAllModelInstances();
|
||||
await createModelsInstanceChunkRequest();
|
||||
await createModelsChunkRequest();
|
||||
await startTargetsWatch();
|
||||
});
|
||||
|
||||
const handleOnCancelViewLogs = useMemoizedFn(async () => {
|
||||
@@ -483,6 +492,7 @@ const Models = forwardRef((props, ref) => {
|
||||
total={dataSource.total}
|
||||
deleteIds={dataSource.deletedIds}
|
||||
filterValues={filterValues}
|
||||
targetList={targetList}
|
||||
></TableList>
|
||||
</TableProvider>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user