feat: scheduler live status — endpoint + UI polling every 15s

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-07-17 15:21:32 -05:00
co-authored by Claude Sonnet 4.6
parent 9d79fe932b
commit 467a24baa4
2 changed files with 57 additions and 3 deletions
+20
View File
@@ -73,6 +73,26 @@ async def shutdown():
_scheduler.shutdown(wait=False)
@app.get("/api/scheduler/status")
async def scheduler_status():
from fastapi.responses import JSONResponse
from app.database import get_connection
job = _scheduler.get_job("wa_sync_recientes")
next_run = job.next_run_time.isoformat() if job and job.next_run_time else None
conn = get_connection()
row = conn.execute(
"SELECT created_at, total_procesados, total_errores, origen "
"FROM sync_wa_log WHERE origen='scheduler' ORDER BY id DESC LIMIT 1"
).fetchone()
conn.close()
return JSONResponse({
"running": _scheduler.running,
"job_exists": job is not None,
"next_run": next_run,
"ultimo_log": dict(row) if row else None,
})
@app.get("/")
async def root():
return RedirectResponse(url="/dashboard")