perf: fetches parallèles + /api/health expose vigilance freshness
Some checks are pending
Deploy info-canicule / deploy (push) Waiting to run
Some checks are pending
Deploy info-canicule / deploy (push) Waiting to run
- /departement/[code] : Promise.allSettled sur les 3 fetches externes (vigilance MF, climato data.gouv, hourly SYNOP). Avant : ~15-20s sériel cold-fetch. Après : ~10s max (= temps du plus lent = climato). - normales (3 ranges) : Promise.all aussi, économise ~30 ms. - /api/health enrichi avec vigilance.productDatetime + ageSeconds pour permettre au cron freshness de checker sans /api/vigilance (qui a été supprimé en public). Pré-requis pour le cron warmup côté infra repo (cf. scripts/cron-warmup-info-canicule.sh). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
ecac3fbf8a
commit
b342ea7375
2 changed files with 55 additions and 33 deletions
|
|
@ -1,22 +1,40 @@
|
|||
import type { APIRoute } from 'astro';
|
||||
import { pingCache } from '../../lib/cache';
|
||||
import { getVigilanceSnapshot } from '../../lib/vigilance';
|
||||
|
||||
export const prerender = false;
|
||||
|
||||
// Endpoint d'usage interne : UptimeRobot (uptime) + cron HC.io freshness.
|
||||
// Pas de CORS (pas destiné aux clients tiers).
|
||||
export const GET: APIRoute = async () => {
|
||||
const cacheOk = await pingCache();
|
||||
|
||||
// Best-effort : récupère le snapshot Vigilance pour exposer la fraîcheur.
|
||||
// Si KO, on dégrade sans casser le health (l'uptime reste vert).
|
||||
let vigilance: { productDatetime: string | null; ageSeconds: number | null } | null = null;
|
||||
try {
|
||||
const snap = await getVigilanceSnapshot();
|
||||
const pd = snap.productDatetime;
|
||||
vigilance = {
|
||||
productDatetime: pd,
|
||||
ageSeconds: pd ? Math.floor((Date.now() - new Date(pd).getTime()) / 1000) : null,
|
||||
};
|
||||
} catch {
|
||||
vigilance = null;
|
||||
}
|
||||
|
||||
const body = {
|
||||
status: cacheOk ? 'ok' : 'degraded',
|
||||
cache: cacheOk,
|
||||
time: new Date().toISOString(),
|
||||
vigilance,
|
||||
};
|
||||
|
||||
return new Response(JSON.stringify(body), {
|
||||
status: cacheOk ? 200 : 503,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Cache-Control': 'no-store',
|
||||
// Pas de CORS : endpoint d'usage interne (UptimeRobot + cron HC.io freshness).
|
||||
// Pas destiné aux clients tiers.
|
||||
},
|
||||
});
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue