MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / usePollEnvironmentHealth

Function usePollEnvironmentHealth

console/src/store/environments.ts:360–398  ·  view source on GitHub ↗
(options: { intervalMs: number })

Source from the content-addressed store, hash-verified

358 * Polls for region information and environment health.
359 */
360export const usePollEnvironmentHealth = (options: { intervalMs: number }) => {
361 const mergeEnvironments = useSetAtom(mergeEnvironmentsWithHealth);
362 const cloudRegions = useAtomValue(cloudRegionsSelector);
363 const appConfig = useAtomValue(appConfigAtom);
364
365 // appConfig is intentionally excluded from queryKey — appConfig.consoleUrl
366 // is a live window.location reference that changes on every navigation,
367 // which would mint a new cache key on each route change and cause
368 // useSuspenseQuery to re-throw. mergeEnvironments is a stable useSetAtom
369 // reference.
370 // eslint-disable-next-line @tanstack/query/exhaustive-deps
371 useSuspenseQuery({
372 queryKey: [...environmentQueryKeys.environmentHealth(cloudRegions)],
373 // Back off to the slower interval once healthy; a steady environment is
374 // already proven reachable, so frequent health checks just burn connection
375 // slots. Poll fast until then so bootstrap transitions surface promptly.
376 refetchInterval: (query) =>
377 allEnvironmentsHealthy(query.state.data)
378 ? options.intervalMs
379 : BOOTSTRAP_POLL_INTERVAL_MS,
380 queryFn: async () => {
381 return Sentry.startSpan(
382 {
383 name: "poll-environment-health",
384 op: "http.client",
385 attributes: { polled: true },
386 },
387 async () => {
388 const result = await fetchEnvironmentsWithHealth({
389 cloudRegions,
390 appConfig,
391 });
392 mergeEnvironments(result);
393 return result;
394 },
395 );
396 },
397 });
398};
399
400const loadableEnvironmentsWithHealth = loadable(environmentsWithHealth);
401/**

Callers 2

useAppInitializerFunction · 0.90

Calls 2

allEnvironmentsHealthyFunction · 0.85

Tested by

no test coverage detected