fix: reduce diagnosticos batch 500→200, add start_from resume param
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
97f4561283
commit
9d79fe932b
@@ -45,8 +45,11 @@ async def erp_sync_now(
|
||||
|
||||
|
||||
@router.post("/erp/sync-diagnosticos")
|
||||
async def erp_sync_diagnosticos(user: dict = Depends(get_current_user)):
|
||||
"""Migra los 12.422 diagnósticos CIE-10 de Firebird → WhatsApp en lotes de 500."""
|
||||
async def erp_sync_diagnosticos(
|
||||
user: dict = Depends(get_current_user),
|
||||
start_from: int = Query(default=0, ge=0, description="Índice desde el que reanudar"),
|
||||
):
|
||||
"""Migra los 12.422 diagnósticos CIE-10 de Firebird → WhatsApp en lotes de 200."""
|
||||
try:
|
||||
conn = get_connection()
|
||||
configs = {row["key"]: row["value"] for row in conn.execute("SELECT * FROM config").fetchall()}
|
||||
@@ -72,14 +75,14 @@ async def erp_sync_diagnosticos(user: dict = Depends(get_current_user)):
|
||||
|
||||
diagnosticos = [{"cod": r["COD_DIAG"], "concepto": r["CONCEPTO"]} for r in (rows or [])]
|
||||
total = len(diagnosticos)
|
||||
batch_size = 500
|
||||
batch_size = 200
|
||||
url = f"{wa_url}/api/lab/ingest_diagnosticos.php"
|
||||
headers = {"Content-Type": "application/json", "X-Lab-Key": wa_key}
|
||||
|
||||
insertados = 0
|
||||
errores = []
|
||||
async with httpx.AsyncClient(timeout=60) as client:
|
||||
for i in range(0, total, batch_size):
|
||||
for i in range(start_from, total, batch_size):
|
||||
lote = diagnosticos[i:i + batch_size]
|
||||
try:
|
||||
resp = await client.post(url, json={"rows": lote}, headers=headers)
|
||||
|
||||
Reference in New Issue
Block a user