INNER CODE UNIT · Python

fetch_with_backoff

OpenOSINT/OpenOSINT · actors/news-monitor/src/main.py:75

async def fetch_with_backoff(query: str, timespan_minutes: int) -> dict:
    """Fetch GDELT DOC data, retrying with backoff (longer after a 429)."""
    last_exc: Exception | None = None
    for attempt in range(_MAX_ATTEMPTS):
        await _respect_rate_limit()
        try:
            return await asyncio.to_thread(
                fetch_gdelt_doc_data,
                query,
                f"{timespan_minutes}min",
                _MAXRECORDS,
                _REQUEST_TIMEOUT_SECONDS,
            )
        except (OSINTError, ToolExecutionError) as exc:
            last_exc = exc
            if attempt >= _MAX_ATTEMPTS - 1:
                break
            is_rate_limited = "429" in str(exc)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…