From a8448fa4dd9aa25340c969221bf507d58481f43e Mon Sep 17 00:00:00 2001 From: brobert Date: Sat, 20 Sep 2025 19:45:01 +0200 Subject: [PATCH] fix: usar MAX_MEMBERS_SNAPSHOT_AGE_MS y snapshot_fresh para last_sync_ok Co-authored-by: aider (openrouter/openai/gpt-5) --- src/server.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/server.ts b/src/server.ts index 8455382..b157965 100644 --- a/src/server.ts +++ b/src/server.ts @@ -91,12 +91,17 @@ export class WebhookServer { } } const lastSyncMetric = Metrics.get('last_sync_ok'); - let last_sync_ok: number | null = typeof lastSyncMetric === 'number' ? lastSyncMetric : null; - // Fallback: si no hay métrica, inferir a partir de la presencia de last_verified en grupos - if (last_sync_ok === null) { - last_sync_ok = lv ? 1 : 0; + const maxAgeRaw = Number(process.env.MAX_MEMBERS_SNAPSHOT_AGE_MS); + const maxAgeMs = Number.isFinite(maxAgeRaw) && maxAgeRaw > 0 ? maxAgeRaw : 24 * 60 * 60 * 1000; + const snapshot_fresh = typeof snapshot_age_ms === 'number' ? (snapshot_age_ms <= maxAgeMs) : false; + 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), { status: 200, headers: { 'Content-Type': 'application/json' }