From 6db28717852e3e92166655137a24bbbd8df8cdda Mon Sep 17 00:00:00 2001 From: "Claude (Opus 4.6)" Date: Tue, 24 Mar 2026 22:12:22 +0000 Subject: [PATCH] [claude] Phase 2: move portal health probe to data/loaders (#411) (#462) --- modules/data/loaders.js | 19 +++++++++++++++++++ modules/weather.js | 17 ++--------------- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/modules/data/loaders.js b/modules/data/loaders.js index a0da6a8..e536c30 100644 --- a/modules/data/loaders.js +++ b/modules/data/loaders.js @@ -18,6 +18,25 @@ export async function fetchSoulMd() { } } +// --- Portal health probes --- +export async function checkPortalHealth(portals) { + for (const portal of portals) { + if (!portal.destination?.url) { + portal.status = 'offline'; + continue; + } + try { + await fetch(portal.destination.url, { + mode: 'no-cors', + signal: AbortSignal.timeout(5000), + }); + portal.status = 'online'; + } catch { + portal.status = 'offline'; + } + } +} + // --- portals.json --- export async function fetchPortals() { const res = await fetch('./portals.json'); diff --git a/modules/weather.js b/modules/weather.js index 9fcbfd4..8fa1cac 100644 --- a/modules/weather.js +++ b/modules/weather.js @@ -5,6 +5,7 @@ import { cloudMaterial } from './platform.js'; import { rebuildRuneRing } from './effects.js'; import { S } from './state.js'; import { fetchWeatherData } from './data/weather.js'; +import { checkPortalHealth } from './data/loaders.js'; // === PORTAL HEALTH CHECKS === const PORTAL_HEALTH_CHECK_MS = 5 * 60 * 1000; @@ -23,21 +24,7 @@ export function setWeatherPortalRefs(portals, portalGroup, rebuildGravityZones) export async function runPortalHealthChecks() { if (_portalsRef.length === 0) return; - for (const portal of _portalsRef) { - if (!portal.destination?.url) { - portal.status = 'offline'; - continue; - } - try { - await fetch(portal.destination.url, { - mode: 'no-cors', - signal: AbortSignal.timeout(5000), - }); - portal.status = 'online'; - } catch { - portal.status = 'offline'; - } - } + await checkPortalHealth(_portalsRef); rebuildRuneRing(); if (_rebuildGravityZonesFn) _rebuildGravityZonesFn();