fix: usar MAX_MEMBERS_SNAPSHOT_AGE_MS y snapshot_fresh para last_sync_ok

Co-authored-by: aider (openrouter/openai/gpt-5) <aider@aider.chat>
pull/1/head
brobert 1 month ago
parent 753e0688ec
commit a8448fa4dd

@ -91,12 +91,17 @@ export class WebhookServer {
} }
} }
const lastSyncMetric = Metrics.get('last_sync_ok'); const lastSyncMetric = Metrics.get('last_sync_ok');
let last_sync_ok: number | null = typeof lastSyncMetric === 'number' ? lastSyncMetric : null; const maxAgeRaw = Number(process.env.MAX_MEMBERS_SNAPSHOT_AGE_MS);
// Fallback: si no hay métrica, inferir a partir de la presencia de last_verified en grupos const maxAgeMs = Number.isFinite(maxAgeRaw) && maxAgeRaw > 0 ? maxAgeRaw : 24 * 60 * 60 * 1000;
if (last_sync_ok === null) { const snapshot_fresh = typeof snapshot_age_ms === 'number' ? (snapshot_age_ms <= maxAgeMs) : false;
last_sync_ok = lv ? 1 : 0; let last_sync_ok: number;
if (typeof lastSyncMetric === 'number') {
last_sync_ok = (lastSyncMetric === 1 && snapshot_fresh) ? 1 : 0;
} else {
// Si no hay métrica explícita, nos basamos exclusivamente en la frescura de la snapshot
last_sync_ok = snapshot_fresh ? 1 : 0;
} }
const payload = { status: 'ok', active_groups, active_members, last_sync_at, snapshot_age_ms, last_sync_ok }; const payload = { status: 'ok', active_groups, active_members, last_sync_at, snapshot_age_ms, snapshot_fresh, last_sync_ok };
return new Response(JSON.stringify(payload), { return new Response(JSON.stringify(payload), {
status: 200, status: 200,
headers: { 'Content-Type': 'application/json' } headers: { 'Content-Type': 'application/json' }

Loading…
Cancel
Save