fix: Agent survives slow Hub on large syncs (25-product chunks, 120s timeout, retry) and keeps heartbeating during jobs; 1.1.4

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
gti
2026-09-24 09:33:54 -03:00
co-authored by Claude Sonnet 5
parent d1104589cc
commit e40e9500a4
19 changed files with 75 additions and 26 deletions
+9 -2
View File
@@ -1,13 +1,20 @@
import httpx
class HubClient:
def __init__(self, url, token, chunk_size=100): self.url, self.token, self.chunk_size = url.rstrip("/"), token, chunk_size
def __init__(self, url, token, chunk_size=25): self.url, self.token, self.chunk_size = url.rstrip("/"), token, chunk_size
def _headers(self): return {"Authorization": f"Bearer {self.token}"}
def classify_batch(self, products):
results = []
for start in range(0, len(products), self.chunk_size):
chunk = products[start:start + self.chunk_size]
response = httpx.post(f"{self.url}/v1/classify/batch", json={"products": chunk}, headers=self._headers(), timeout=60)
# Small chunks + generous timeout + one retry: a large first sync must survive a
# slow Hub / reverse-proxy read timeout instead of failing the whole job.
for attempt in (1, 2):
try:
response = httpx.post(f"{self.url}/v1/classify/batch", json={"products": chunk}, headers=self._headers(), timeout=120)
break
except httpx.ReadTimeout:
if attempt == 2: raise
response.raise_for_status(); results.extend(response.json()["results"])
return results
def get_json(self, path):