From dcbaa947747c54d43a11259169210f17fdadb1da Mon Sep 17 00:00:00 2001 From: marsalva Date: Thu, 19 Mar 2026 08:20:29 +0000 Subject: [PATCH] Actualizar server.js --- server.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/server.js b/server.js index 29d0159..f5a46ef 100644 --- a/server.js +++ b/server.js @@ -3925,8 +3925,15 @@ setInterval(async () => { const cpMatch = todoElTexto.match(/\b\d{5}\b/); const cpFinal = cpMatch ? cpMatch[0] : "00000"; - // 🔥 Disparamos la bolsa - await dispatchToBolsa(svc.id, finalGuildId, cpFinal, svc.owner_id, null); + // 🔥 Disparamos la bolsa y guardamos el resultado + const dispatchResult = await dispatchToBolsa(svc.id, finalGuildId, cpFinal, svc.owner_id, null); + + // 🛑 ESCUDO ANTI-BUCLE: Si falla porque no hay operarios en ese CP, + // marcamos la urgencia como "failed" para que el reloj deje de intentarlo eternamente. + if (!dispatchResult.ok) { + console.log(`🛑 [ESCUDO] Abortando bucle para #${svc.service_ref}. Marcado como 'failed'.`); + await client.query("UPDATE scraped_services SET automation_status = 'failed' WHERE id = $1", [svc.id]); + } } }