diff --git a/app/templates/envios_erp.html b/app/templates/envios_erp.html index cf9f4da..895c2f7 100644 --- a/app/templates/envios_erp.html +++ b/app/templates/envios_erp.html @@ -196,13 +196,11 @@ async function pollSchedulerStatus() { } const parts = []; if (d.next_run) { - const nx = new Date(d.next_run); - parts.push(`Próxima ejecución: ${nx.toLocaleTimeString('es-CO')}`); + parts.push(`Próxima ejecución: ${d.next_run}`); } if (d.ultimo_log) { const ul = d.ultimo_log; - const ts = new Date(ul.created_at).toLocaleTimeString('es-CO'); - parts.push(`Último sync scheduler: ${ts} · ${ul.total ?? 0} procesados, ${ul.errores ?? 0} errores`); + parts.push(`Último sync scheduler: ${ul.hora} · ${ul.total ?? 0} procesados, ${ul.errores ?? 0} errores`); } live.innerHTML = parts.join(''); } catch(_) {} diff --git a/main.py b/main.py index 8c8f5ec..978229d 100644 --- a/main.py +++ b/main.py @@ -77,19 +77,36 @@ async def shutdown(): async def scheduler_status(): from fastapi.responses import JSONResponse from app.database import get_connection + from datetime import timezone, timedelta + COL = timezone(timedelta(hours=-5)) + job = _scheduler.get_job("wa_sync_recientes") - next_run = job.next_run_time.isoformat() if job and job.next_run_time else None + next_run_str = None + if job and job.next_run_time: + next_run_str = job.next_run_time.astimezone(COL).strftime("%H:%M:%S") + conn = get_connection() row = conn.execute( - "SELECT created_at, total, errores, origen " - "FROM sync_wa_log WHERE origen='scheduler' ORDER BY id DESC LIMIT 1" + "SELECT created_at, total, errores FROM sync_wa_log " + "WHERE origen='scheduler' ORDER BY id DESC LIMIT 1" ).fetchone() conn.close() + + ultimo = None + if row: + from datetime import datetime + ts_utc = datetime.fromisoformat(row["created_at"].replace(" ", "T") + "+00:00") + ultimo = { + "hora": ts_utc.astimezone(COL).strftime("%H:%M:%S"), + "total": row["total"], + "errores": row["errores"], + } + return JSONResponse({ - "running": _scheduler.running, + "running": _scheduler.running, "job_exists": job is not None, - "next_run": next_run, - "ultimo_log": dict(row) if row else None, + "next_run": next_run_str, + "ultimo_log": ultimo, })