2026-05-14 23:50:03 +00:00
|
|
|
import { useQuery } from "@tanstack/react-query";
|
|
|
|
|
import { useInstances } from "@/hooks/useInstances";
|
|
|
|
|
import { checkConnection } from "@/lib/config";
|
|
|
|
|
|
|
|
|
|
const POLL_INTERVAL_MS = 30_000;
|
|
|
|
|
|
|
|
|
|
export function useHealthStatus() {
|
|
|
|
|
const { active } = useInstances();
|
|
|
|
|
return useQuery({
|
2026-05-28 05:31:46 +04:00
|
|
|
queryKey: ["health", active?.id, active?.baseUrl, Boolean(active?.token)],
|
2026-05-14 23:50:03 +00:00
|
|
|
queryFn: async () => {
|
|
|
|
|
if (!active) throw new Error("No active instance");
|
|
|
|
|
return checkConnection(active.baseUrl, active.token || undefined);
|
|
|
|
|
},
|
|
|
|
|
enabled: !!active,
|
|
|
|
|
refetchInterval: POLL_INTERVAL_MS,
|
|
|
|
|
refetchOnWindowFocus: true,
|
|
|
|
|
staleTime: 0,
|
|
|
|
|
});
|
|
|
|
|
}
|