From 9a9fde7caaba6ccba3be2a168a5185775d549c41 Mon Sep 17 00:00:00 2001 From: ztimson Date: Wed, 24 Jun 2026 13:31:58 -0400 Subject: [PATCH] 24h forecasting --- server/src/forecast.mjs | 14 +++++++------- server/src/server.mjs | 5 ++--- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/server/src/forecast.mjs b/server/src/forecast.mjs index a5b3a77..558d6d0 100644 --- a/server/src/forecast.mjs +++ b/server/src/forecast.mjs @@ -2,7 +2,7 @@ import {queryHourly, getCoords, queryCurrent} from './influx.mjs'; import { getCelestialForecast } from './celestial.mjs'; -let cache = { ts: 0, slots: [], summary: null } +export let lastForecast = { ts: 0, slots: [], summary: null } const TTL = 10 * 60 * 1000 // ── Physics Helpers ─────────────────────────────────────────────────────────── @@ -224,14 +224,14 @@ function summarise(slots) { export async function refreshForecast() { const sensors = await queryCurrent().catch(() => null) - if (!sensors) return cache + if (!sensors) return lastForecast const slots = await get24HourForecast(sensors).catch(() => null) - if (!slots) return cache - cache = { ts: Date.now(), slots, summary: summarise(slots) } - return cache + if (!slots) return lastForecast + lastForecast = { ts: Date.now(), slots, summary: summarise(slots) } + return lastForecast } export async function ensureForecast() { - if (Date.now() - cache.ts > TTL) await refreshForecast() - return cache + if (Date.now() - lastForecast.ts > TTL) await refreshForecast() + return lastForecast } diff --git a/server/src/server.mjs b/server/src/server.mjs index ec3feaf..7e44815 100644 --- a/server/src/server.mjs +++ b/server/src/server.mjs @@ -10,8 +10,7 @@ import {spec} from './spec.mjs'; import {existsSync} from 'fs'; import {getAirTraffic, getAirTrafficHistory, getShapes} from './airtraffic.mjs'; import {getWeatherCondition} from './openweather.mjs'; -import {refreshForecast} from './forecast.mjs'; -import {cache} from 'express/lib/application.js'; +import {lastForecast, refreshForecast} from './forecast.mjs'; const app = express(); const DIR = dirname(fileURLToPath(import.meta.url)); @@ -186,7 +185,7 @@ let ready = false while (!ready) { try { await refreshForecast() - ready = cache.slots.length > 0 + ready = lastForecast.slots.length > 0 } catch {} if (!ready) await new Promise(r => setTimeout(r, 5000)) }