added dampandmouldandrepaircomments, more resilence on retries with hubspot api

This commit is contained in:
Jun-te Kim 2026-04-02 10:19:40 +00:00
parent acb44dc60a
commit e1ea6f79f9

View file

@ -91,14 +91,18 @@ class HubspotClient:
Call fn(), retrying up to max_retries times on 429 rate-limit errors. Call fn(), retrying up to max_retries times on 429 rate-limit errors.
Waits the minimal amount: the remaining interval window reported by HubSpot headers. Waits the minimal amount: the remaining interval window reported by HubSpot headers.
Falls back to the full interval (10s) if headers are absent. Falls back to the full interval (10s) if headers are absent.
Note: each HubSpot sub-module (deals, companies, etc.) ships its own ApiException
class with no shared base beyond Exception, so we detect 429s via duck-typing.
""" """
for attempt in range(max_retries + 1): for attempt in range(max_retries + 1):
try: try:
return fn() return fn()
except ApiException as e: except Exception as e:
if e.status != 429 or attempt == max_retries: status = getattr(e, "status", None)
if status != 429 or attempt == max_retries:
raise raise
headers = e.headers or {} headers = getattr(e, "headers", None) or {}
interval_ms = int( interval_ms = int(
headers.get("x-hubspot-ratelimit-interval-milliseconds", 10000) headers.get("x-hubspot-ratelimit-interval-milliseconds", 10000)
) )