complete source discovery processing lifecycle

This commit is contained in:
Marco0300
2026-09-03 23:01:25 +02:00
parent a9213c0282
commit 58c4d93208
4 changed files with 157 additions and 18 deletions
+8 -2
View File
@@ -85,10 +85,16 @@ def backoff_delay(attempt: int, base: float = 0.5, maximum: float = 30.0, jitter
return exponential_backoff(attempt, base, maximum, jitter)
def circuit_is_open(consecutive_failures: int, threshold: int = 3) -> bool:
return int(consecutive_failures) >= threshold
return int(consecutive_failures) >= max(1, int(threshold))
def quota_remaining(used: int, limit: int | None) -> int | None:
"""Return remaining quota, clamped so malformed values fail closed."""
if limit is None: return None
return max(0, int(limit) - max(0, int(used)))
def quota_allowed(used: int, limit: int | None) -> bool:
return limit is None or (limit >= 0 and used < limit)
remaining = quota_remaining(used, limit)
return remaining is None or remaining > 0
def rate_limit_delay(last_request: float | None, min_interval: float) -> float:
if last_request is None: return 0.0