1.44
This commit is contained in:
parent
c1ef996bbb
commit
3667ab1a97
@ -84,6 +84,7 @@ const LogViewerContent: React.FC<{
|
||||
const onCloseReadyRef = useRef(onCloseReady);
|
||||
const onStatusChangeRef = useRef(onStatusChange);
|
||||
const updateWindowTitleRef = useRef(updateWindowTitle);
|
||||
const prevPodNameRef = useRef<string>('');
|
||||
|
||||
// 保持最新的回调引用和状态
|
||||
useEffect(() => {
|
||||
@ -190,6 +191,62 @@ const LogViewerContent: React.FC<{
|
||||
handleStartRef.current = 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数据源
|
||||
const dataSource = useMemo(() => {
|
||||
console.log('[LogWindowManager] Creating new dataSource for app:', app.teamApplicationId, app.runtimeType);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user