|
7 | 7 |
|
8 | 8 | import pandas as pd
|
9 | 9 | from fastapi import HTTPException
|
| 10 | +from httpcore import NetworkError, TimeoutException |
| 11 | +from httpx import RequestError |
10 | 12 | from pydantic import BaseModel
|
| 13 | +from requests.exceptions import ConnectionError, Timeout |
11 | 14 |
|
12 | 15 | from ..common.utils.cozo import uuid_int_list_to_uuid4
|
13 | 16 | from ..env import do_verify_developer, do_verify_developer_owns_resource
|
@@ -254,7 +257,21 @@ def wrapper(*args: P.args, client=None, **kwargs: P.kwargs) -> pd.DataFrame:
|
254 | 257 |
|
255 | 258 | debug and print(repr(e))
|
256 | 259 |
|
257 |
| - if "busy" in (str(e) + str(getattr(e, "resp", e))).lower(): |
| 260 | + pretty_error = repr(e).lower() |
| 261 | + cozo_busy = ("busy" in pretty_error) or ( |
| 262 | + "when executing against relation '_" in pretty_error |
| 263 | + ) |
| 264 | + connection_error = isinstance( |
| 265 | + e, |
| 266 | + ( |
| 267 | + ConnectionError, |
| 268 | + Timeout, |
| 269 | + TimeoutException, |
| 270 | + NetworkError, |
| 271 | + RequestError, |
| 272 | + ), |
| 273 | + ) |
| 274 | + if cozo_busy or connection_error: |
258 | 275 | raise HTTPException(
|
259 | 276 | status_code=429, detail="Resource busy. Please try again later."
|
260 | 277 | ) from e
|
@@ -321,9 +338,10 @@ def is_resource_busy(e: Exception) -> bool:
|
321 | 338 | return isinstance(e, HTTPException) and e.status_code == 429
|
322 | 339 |
|
323 | 340 | @retry(
|
324 |
| - stop=stop_after_attempt(4), |
325 |
| - wait=wait_exponential(multiplier=1, min=4, max=10), |
| 341 | + stop=stop_after_attempt(6), |
| 342 | + wait=wait_exponential(multiplier=1.2, min=3, max=10), |
326 | 343 | retry=retry_if_exception(is_resource_busy),
|
| 344 | + reraise=True, |
327 | 345 | )
|
328 | 346 | @wraps(func)
|
329 | 347 | async def wrapper(
|
@@ -367,7 +385,21 @@ async def wrapper(
|
367 | 385 |
|
368 | 386 | debug and print(repr(e))
|
369 | 387 |
|
370 |
| - if "busy" in (str(e) + str(getattr(e, "resp", e))).lower(): |
| 388 | + pretty_error = repr(e).lower() |
| 389 | + cozo_busy = ("busy" in pretty_error) or ( |
| 390 | + "when executing against relation '_" in pretty_error |
| 391 | + ) |
| 392 | + connection_error = isinstance( |
| 393 | + e, |
| 394 | + ( |
| 395 | + ConnectionError, |
| 396 | + Timeout, |
| 397 | + TimeoutException, |
| 398 | + NetworkError, |
| 399 | + RequestError, |
| 400 | + ), |
| 401 | + ) |
| 402 | + if cozo_busy or connection_error: |
371 | 403 | raise HTTPException(
|
372 | 404 | status_code=429, detail="Resource busy. Please try again later."
|
373 | 405 | ) from e
|
|
0 commit comments