feat(sync-log): historial de sincronizaciones WhatsApp en sync_wa_log

- Nueva tabla sync_wa_log (total, created, skipped, updated, errores, origen, modo)
- Log guardado en /pacientes/sync-all, /terceros/send y /automation/run
- Ruta GET /pacientes/historial devuelve últimos 100 registros
- UI: tabla de historial con origen, modo, conteos y detalle de errores

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-07-09 11:13:28 -05:00
co-authored by Claude Sonnet 4.6
parent 1aab14f705
commit b0175a2ca5
6 changed files with 174 additions and 7 deletions
+3 -4
View File
@@ -13,7 +13,7 @@ from app.services.json_generator import (
agrupar_por_recepcion,
)
from app.services.api_client import get_tns_token, TNS_BASE
from app.services.whatsapp_sync import sync_paciente
from app.services.whatsapp_sync import sync_paciente, sync_todos, guardar_sync_log
router = APIRouter(prefix="/automation", tags=["automation"])
@@ -266,9 +266,8 @@ async def run_automation(
if wa_url and wa_key and rows_pac:
ingest_url = f"{wa_url}/api/lab/ingest_paciente.php"
try:
async with httpx.AsyncClient(timeout=timeout) as wa_client:
for row in rows_pac:
await sync_paciente(row, ingest_url, wa_key, wa_client)
wa_resultado = await sync_todos(rows_pac, ingest_url, wa_key, timeout, modo="upsert")
guardar_sync_log(wa_resultado, user["user_id"], origen="automation", modo="upsert")
except Exception:
pass