fix: parallelize WA sync and surface scheduler errors in historial

- whatsapp_sync: send patients concurrently (asyncio.gather + semaphore=10) instead of sequentially — eliminates long waits with many patients
- envios_erp: auto-refresh historial every 60s when scheduler tab is active
- main: wrap scheduler job to catch exceptions and log them to sync_wa_log so failures are visible in historial

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-07-23 11:34:30 -05:00
co-authored by Claude Sonnet 4.6
parent 5ca97159b4
commit cffeae7e94
3 changed files with 61 additions and 21 deletions
+12 -4
View File
@@ -151,6 +151,7 @@ const _TAB_ACTIVE = 'border-green-500 text-green-700 bg-green-50';
const _TAB_INACTIVE = 'border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300';
let _schedulerLoaded = false;
let _histRefreshTimer = null;
function switchTab(name) {
document.querySelectorAll('.tab-panel').forEach(p => p.classList.add('hidden'));
@@ -168,10 +169,17 @@ function switchTab(name) {
const iframe = document.getElementById('iframe-pacientes');
if (!iframe.src) iframe.src = '/pacientes?embed=1';
}
if (name === 'scheduler' && !_schedulerLoaded) {
_schedulerLoaded = true;
cargarHistorialScheduler();
pollSchedulerStatus();
if (name === 'scheduler') {
if (!_schedulerLoaded) {
_schedulerLoaded = true;
cargarHistorialScheduler();
pollSchedulerStatus();
}
// Auto-refresh historial cada 60s mientras el tab está activo
clearInterval(_histRefreshTimer);
_histRefreshTimer = setInterval(cargarHistorialScheduler, 60000);
} else {
clearInterval(_histRefreshTimer);
}
sessionStorage.setItem('erp-tab', name);