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
+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,
})