fix: format scheduler times in Colombia UTC-5 server-side

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-07-17 15:31:40 -05:00
co-authored by Claude Sonnet 4.6
parent 12f5f1388d
commit 83c8b2aa0b
2 changed files with 25 additions and 10 deletions
+2 -4
View File
@@ -196,13 +196,11 @@ async function pollSchedulerStatus() {
}
const parts = [];
if (d.next_run) {
const nx = new Date(d.next_run);
parts.push(`<span><i class="fas fa-clock mr-1 text-blue-400"></i>Próxima ejecución: <strong>${nx.toLocaleTimeString('es-CO')}</strong></span>`);
parts.push(`<span><i class="fas fa-clock mr-1 text-blue-400"></i>Próxima ejecución: <strong>${d.next_run}</strong></span>`);
}
if (d.ultimo_log) {
const ul = d.ultimo_log;
const ts = new Date(ul.created_at).toLocaleTimeString('es-CO');
parts.push(`<span><i class="fas fa-history mr-1 text-purple-400"></i>Último sync scheduler: <strong>${ts}</strong> · ${ul.total ?? 0} procesados, ${ul.errores ?? 0} errores</span>`);
parts.push(`<span><i class="fas fa-history mr-1 text-purple-400"></i>Último sync scheduler: <strong>${ul.hora}</strong> · ${ul.total ?? 0} procesados, ${ul.errores ?? 0} errores</span>`);
}
live.innerHTML = parts.join('');
} catch(_) {}
+23 -6
View File
@@ -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,
})