From 83c2e655f6af8cf425ff0694f3645f444f10acc9 Mon Sep 17 00:00:00 2001 From: ztimson Date: Wed, 24 Jun 2026 16:36:20 -0400 Subject: [PATCH] Fixing current forecast --- server/src/forecast.mjs | 14 ++++---------- server/src/server.mjs | 6 +++--- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/server/src/forecast.mjs b/server/src/forecast.mjs index 9b7a753..cbbe938 100644 --- a/server/src/forecast.mjs +++ b/server/src/forecast.mjs @@ -4,7 +4,7 @@ import { getCelestialForecast } from './celestial.mjs'; import {getWeatherCondition} from './openweather.mjs'; export let lastForecast = { ts: 0, slots: [], summary: null } -const TTL = 10 * 60 * 1000 +export const forecastTTL = 5 * 60 * 60_000 // ── Physics Helpers ─────────────────────────────────────────────────────────── @@ -234,17 +234,11 @@ function summarise(slots) { } export async function getForecast() { - if(Date.now() - lastForecast.ts < TTL) return lastForecast; + if(Date.now() - lastForecast.ts < forecastTTL) return lastForecast; const sensors = await queryCurrent().catch(() => null) - if(!sensors) { - console.log('no sensors, bailing'); - return lastForecast - } + if(!sensors) return lastForecast const slots = await get24HourForecast(sensors).catch(() => null) - if(!slots) { - console.log('no slots, bailing') - return lastForecast - } + if(!slots) return lastForecast lastForecast = { ts: Date.now(), slots, summary: summarise(slots) } return lastForecast } diff --git a/server/src/server.mjs b/server/src/server.mjs index 83ada25..ff1d933 100644 --- a/server/src/server.mjs +++ b/server/src/server.mjs @@ -10,7 +10,7 @@ import {spec} from './spec.mjs'; import {existsSync} from 'fs'; import {getAirTraffic, getAirTrafficHistory, getShapes} from './airtraffic.mjs'; import {getWeatherCondition} from './openweather.mjs'; -import {lastForecast, getForecast} from './forecast.mjs'; +import {lastForecast, getForecast, forecastTTL} from './forecast.mjs'; import {dailyWeather, hourlyWeather} from './openmeteo.mjs'; const app = express(); @@ -182,8 +182,8 @@ app.get('*', (req, res) => { // ── Start ───────────────────────────────────────────────────────────────────── const c = cfg(); -setTimeout(getForecast, 2000) -setInterval(getForecast, 10 * 60 * 1000) +setTimeout(getForecast, 1) +setInterval(getForecast, forecastTTL) app.listen(c.PORT, () => { console.log(`🌦 Weather API — http://localhost:${c.PORT}`)