fix self heal
This commit is contained in:
@@ -108,6 +108,31 @@ def _read_last_db_progress_ts(redis_client: Redis) -> int | None:
|
||||
return max_ts or None
|
||||
|
||||
|
||||
def _has_active_recent_progress(redis_client: Redis, now_ts: int, stall_seconds: int) -> bool:
|
||||
"""Return True when a task is still reporting non-DB progress.
|
||||
|
||||
Hourly only_new runs can legitimately skip every listed vehicle as existing.
|
||||
Those runs may not emit fast_db_progress for a long time, but they still emit
|
||||
regular listing/segment progress. Treating old DB timestamps as fatal caused
|
||||
the watchdog to kill healthy production workers during such scans.
|
||||
"""
|
||||
for key in redis_client.scan_iter(match="iaai:state:task_progress:*"):
|
||||
try:
|
||||
payload = redis_client.get(key)
|
||||
if not payload:
|
||||
continue
|
||||
data = json.loads(payload)
|
||||
stage = str(data.get("stage") or "")
|
||||
if stage in {"failed", "sync_done", "segment_task_failed", "segment_task_soft_timeout"}:
|
||||
continue
|
||||
ts = _safe_int(data.get("ts"), 0)
|
||||
if ts > 0 and now_ts - ts <= max(60, int(stall_seconds)):
|
||||
return True
|
||||
except Exception:
|
||||
continue
|
||||
return False
|
||||
|
||||
|
||||
def _reset_bootstrap_checkpoint_for_db_idle(redis_client: Redis) -> None:
|
||||
pipe = redis_client.pipeline()
|
||||
pipe.delete(SYNC_LISTING_CHECKPOINT_KEY)
|
||||
@@ -219,6 +244,12 @@ def main() -> None:
|
||||
restart_reason = f"progress_age={age}s > {stall_seconds}s"
|
||||
db_idle_restart = False
|
||||
if age <= stall_seconds:
|
||||
# If the task is actively reporting progress, do not require DB writes.
|
||||
# Hourly only_new listing scans often skip already-known cars and can
|
||||
# legitimately have no DB writes while still moving through segments.
|
||||
if _has_active_recent_progress(redis_client, now_ts, stall_seconds):
|
||||
time.sleep(check_interval)
|
||||
continue
|
||||
last_db_ts = _read_last_db_progress_ts(redis_client)
|
||||
db_age = None if last_db_ts is None else max(0, now_ts - int(last_db_ts))
|
||||
if db_age is None:
|
||||
|
||||
Reference in New Issue
Block a user