Fixing current forecast

This commit is contained in:
2026-06-24 16:36:20 -04:00
parent d20ef97cf1
commit 83c2e655f6
2 changed files with 7 additions and 13 deletions

View File

@@ -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
}

View File

@@ -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}`)