Actualizar robot.js

This commit is contained in:
2026-03-22 20:45:08 +00:00
parent 6c4675482b
commit f996947f68

View File

@@ -197,13 +197,14 @@ async function runMultiasistencia(ownerId, user, pass, gremiosDB) {
} }
const expedientes = Array.from(todosExpedientes); const expedientes = Array.from(todosExpedientes);
console.log(`✅ [Multi] Total expedientes detectados: ${expedientes.length}`); console.log(`\n✅ [Multi] TOTAL EXPEDIENTES LEÍDOS EN WEB: ${expedientes.length}`);
console.log(`📋 REFERENCIAS LEÍDAS:`, expedientes.join(', '));
// 🛑 NUEVO SEGURO DE VIDA: Si lee menos de 5, desconfiamos de la web y NO archivamos nada, por si es un error puntual. if (expedientes.length > 0) {
if (expedientes.length > 5 || paginaActual === 1) { console.log(`🧹 Llamando a la escoba (syncAndArchive) con ${expedientes.length} refs...`);
await syncAndArchive(ownerId, 'multiasistencia', expedientes); await syncAndArchive(ownerId, 'multiasistencia', expedientes);
} else { } else {
console.log("⚠️ [Multi] Pocos expedientes detectados. ABORTANDO ARCHIVADO DE SEGURIDAD."); console.log("⚠️ [Multi] ¡CUIDADO! Se han detectado 0 expedientes. ABORTANDO LA ESCOBA para no cerrar nada.");
} }
for (const ref of expedientes) { for (const ref of expedientes) {
@@ -436,7 +437,12 @@ async function syncAndArchive(ownerId, provider, currentWebRefs) {
const missingServices = dbServices.filter(s => !currentWebRefs.includes(s.service_ref)); const missingServices = dbServices.filter(s => !currentWebRefs.includes(s.service_ref));
const refsToArchive = missingServices.map(s => s.service_ref); const refsToArchive = missingServices.map(s => s.service_ref);
console.log(`\n📊 [ESCOBA ${provider.toUpperCase()}] Refs en Web: ${currentWebRefs.length} | Pendientes en BD: ${dbServices.length}`);
if (refsToArchive.length > 0) { if (refsToArchive.length > 0) {
console.log(`🚨 ATENCIÓN: Se van a ARCHIVAR ${refsToArchive.length} expedientes porque NO están en la web:`);
console.log(`💀 LISTA DE CONDENADOS:`, refsToArchive.join(', '));
// 3. Los archivamos (los quitamos del buzón) // 3. Los archivamos (los quitamos del buzón)
await client.query( await client.query(
`UPDATE scraped_services `UPDATE scraped_services