24h forecasting
This commit is contained in:
@@ -223,8 +223,10 @@ function summarise(slots) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function refreshForecast() {
|
export async function refreshForecast() {
|
||||||
const sensors = await queryCurrent()
|
const sensors = await queryCurrent().catch(() => null)
|
||||||
const slots = await get24HourForecast(sensors)
|
if (!sensors) return cache
|
||||||
|
const slots = await get24HourForecast(sensors).catch(() => null)
|
||||||
|
if (!slots) return cache
|
||||||
cache = { ts: Date.now(), slots, summary: summarise(slots) }
|
cache = { ts: Date.now(), slots, summary: summarise(slots) }
|
||||||
return cache
|
return cache
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import {existsSync} from 'fs';
|
|||||||
import {getAirTraffic, getAirTrafficHistory, getShapes} from './airtraffic.mjs';
|
import {getAirTraffic, getAirTrafficHistory, getShapes} from './airtraffic.mjs';
|
||||||
import {getWeatherCondition} from './openweather.mjs';
|
import {getWeatherCondition} from './openweather.mjs';
|
||||||
import {refreshForecast} from './forecast.mjs';
|
import {refreshForecast} from './forecast.mjs';
|
||||||
|
import {cache} from 'express/lib/application.js';
|
||||||
|
|
||||||
const app = express();
|
const app = express();
|
||||||
const DIR = dirname(fileURLToPath(import.meta.url));
|
const DIR = dirname(fileURLToPath(import.meta.url));
|
||||||
@@ -181,7 +182,14 @@ app.get('*', (req, res) => {
|
|||||||
|
|
||||||
// ── Start ─────────────────────────────────────────────────────────────────────
|
// ── Start ─────────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
setTimeout(refreshForecast, 2000)
|
let ready = false
|
||||||
|
while (!ready) {
|
||||||
|
try {
|
||||||
|
await refreshForecast()
|
||||||
|
ready = cache.slots.length > 0
|
||||||
|
} catch {}
|
||||||
|
if (!ready) await new Promise(r => setTimeout(r, 5000))
|
||||||
|
}
|
||||||
setInterval(refreshForecast, 10 * 60 * 1000)
|
setInterval(refreshForecast, 10 * 60 * 1000)
|
||||||
|
|
||||||
const c = cfg();
|
const c = cfg();
|
||||||
|
|||||||
Reference in New Issue
Block a user