This commit is contained in:
dengqichen 2025-12-29 09:36:26 +08:00
parent c1ef996bbb
commit 3667ab1a97

View File

@ -84,6 +84,7 @@ const LogViewerContent: React.FC<{
const onCloseReadyRef = useRef(onCloseReady); const onCloseReadyRef = useRef(onCloseReady);
const onStatusChangeRef = useRef(onStatusChange); const onStatusChangeRef = useRef(onStatusChange);
const updateWindowTitleRef = useRef(updateWindowTitle); const updateWindowTitleRef = useRef(updateWindowTitle);
const prevPodNameRef = useRef<string>('');
// 保持最新的回调引用和状态 // 保持最新的回调引用和状态
useEffect(() => { useEffect(() => {
@ -190,6 +191,62 @@ const LogViewerContent: React.FC<{
handleStartRef.current = handleStart; handleStartRef.current = handleStart;
}, [handleStart]); }, [handleStart]);
// 监听Pod切换自动重启日志流
useEffect(() => {
// 跳过初始化prevPodNameRef为空
if (!prevPodNameRef.current) {
prevPodNameRef.current = podName;
return;
}
// 跳过相同的Pod名称
if (prevPodNameRef.current === podName) {
return;
}
// 只在正在streaming或paused时才重启
if (status !== LogStreamStatus.STREAMING && status !== LogStreamStatus.PAUSED) {
prevPodNameRef.current = podName;
return;
}
console.log('[LogWindowManager] Pod changed from', prevPodNameRef.current, 'to', podName, '- restarting stream');
// 更新引用
prevPodNameRef.current = podName;
// 重启流程STOP → 清空 → START
if (controlApiRef.current) {
// 1. 发送STOP消息
const stopMessage = {
type: 'CONTROL',
data: { request: { action: 'STOP' } },
};
controlApiRef.current.send(JSON.stringify(stopMessage));
// 2. 清空日志
logApiRef.current?.clear();
// 3. 延迟后发送START消息包含新的Pod名称
setTimeout(() => {
if (controlApiRef.current) {
const startMessage = {
type: 'START',
data: {
request: {
lines,
...(app.runtimeType === 'K8S' && podName ? { name: podName } : {}),
},
},
};
console.log('[LogWindowManager] Sending START with new pod:', startMessage);
controlApiRef.current.send(JSON.stringify(startMessage));
setStatus(LogStreamStatus.STREAMING);
}
}, 200);
}
}, [podName, status, lines, app.runtimeType]);
// 创建WebSocket数据源 // 创建WebSocket数据源
const dataSource = useMemo(() => { const dataSource = useMemo(() => {
console.log('[LogWindowManager] Creating new dataSource for app:', app.teamApplicationId, app.runtimeType); console.log('[LogWindowManager] Creating new dataSource for app:', app.teamApplicationId, app.runtimeType);