Actualizar automatizaciones.html

This commit is contained in:
2026-02-15 21:19:56 +00:00
parent 57e49dcc41
commit 7662d4460e

View File

@@ -69,21 +69,33 @@
setInterval(loadAutomations, 20000);
});
async function loadAutomations() {
try {
const res = await fetch(`${API_URL}/providers/scraped`, {
headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` }
});
const data = await res.json();
if (data.ok) {
activeIntervals.forEach(clearInterval);
activeIntervals = [];
async function loadAutomations() {
try {
const res = await fetch(`${API_URL}/providers/scraped`, {
headers: { "Authorization": `Bearer ${localStorage.getItem("token")}` }
});
const data = await res.json();
if (data.ok) {
activeIntervals.forEach(clearInterval);
activeIntervals = [];
renderCards(data.services.filter(s => s.automation_status === 'in_progress'));
renderFailedTable(data.services.filter(s => s.automation_status === 'failed'));
}
} catch (e) { console.error(e); }
// Solo mostramos arriba los que están en progreso Y TIENEN un operario con el turno activo
const inQueue = data.services.filter(s =>
s.automation_status === 'in_progress' && s.current_worker_name !== null
);
// Se consideran fallidos los que están marcados como 'failed'
// O los que están 'in_progress' pero ya no tienen a nadie en turno (ronda terminada)
const failed = data.services.filter(s =>
s.automation_status === 'failed' ||
(s.automation_status === 'in_progress' && s.current_worker_name === null)
);
renderCards(inQueue);
renderFailedTable(failed);
}
} catch (e) { console.error(e); }
}
function renderCards(activeServices) {
const container = document.getElementById('automation-list');