Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 43 additions & 34 deletions src/ui/WatchDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,54 +45,63 @@ export const WatchDashboard = () => {
}, []);

useEffect(() => {
const fetchPods = async () => {
try {
const p = await getRunningPods();
setPods(p);
let isMounted = true;
let isFetching = false;

const fetchData = async () => {
if (isFetching) return;
isFetching = true;

const [podsResult, containersResult, k8sStatsResult, dockerStatsResult] = await Promise.allSettled([
getRunningPods(),
getRunningContainers(),
getK8sClusterStats(),
getDockerSystemStats()
]);

if (!isMounted) {
isFetching = false;
return;
}

if (podsResult.status === 'fulfilled') {
setPods(podsResult.value);
setError(prev => prev?.type === 'k8s' ? null : prev);
} catch (err) {
setError({ type: 'k8s', message: (err as Error).message });
} else {
setError({ type: 'k8s', message: (podsResult.reason as Error).message });
}
};

const fetchContainers = async () => {
try {
const c = await getRunningContainers();
setContainers(c);
if (containersResult.status === 'fulfilled') {
setContainers(containersResult.value);
setError(prev => prev?.type === 'docker' ? null : prev);
} catch (err) {
setError({ type: 'docker', message: (err as Error).message });
} else {
setError({ type: 'docker', message: (containersResult.reason as Error).message });
}
};

const fetchK8sStats = async () => {
try {
const stats = await getK8sClusterStats();
setK8sStats(stats);
} catch (err) {
if (k8sStatsResult.status === 'fulfilled') {
setK8sStats(k8sStatsResult.value);
} else {
setK8sStats(null);
}
};

const fetchDockerStats = async () => {
try {
const stats = await getDockerSystemStats();
setDockerStats(stats);
} catch (err) {
if (dockerStatsResult.status === 'fulfilled') {
setDockerStats(dockerStatsResult.value);
} else {
setDockerStats(null);
}
};

const fetchData = () => {
fetchPods();
fetchContainers();
fetchK8sStats();
fetchDockerStats();
isFetching = false;
};

fetchData();
const interval = setInterval(fetchData, 3000);
return () => clearInterval(interval);
void fetchData();
const interval = setInterval(() => {
void fetchData();
}, 3000);

return () => {
isMounted = false;
clearInterval(interval);
};
}, []);

const isCompact = columns < 80;
Expand Down
Loading