search for standard sites
pub-search.waow.tech
search
zig
blog
atproto
1.3 kB
31 lines
1"""Pure watchdog policy helpers, kept separate from network and auth code."""
2
3# cadence (2h heavypad prefect builds) + build (~20m) + adoption poll (5m) + margin
4SNAPSHOT_AGE_ALERT_MINUTES = 180
5
6
7def snapshot_age_minutes(manifest: object, now_timestamp: float) -> float:
8 if not isinstance(manifest, dict):
9 raise ValueError("snapshot manifest body is not an object")
10 created_at = manifest.get("created_at")
11 if not isinstance(created_at, (int, float)) or created_at <= 0:
12 raise ValueError("snapshot manifest has invalid created_at")
13 return (now_timestamp - created_at) / 60
14
15
16def snapshot_age_problem(manifest: object, now_timestamp: float) -> str | None:
17 if not isinstance(manifest, dict):
18 return "snapshot manifest body is not an object"
19
20 build_id = manifest.get("build_id", "?")
21 created_at = manifest.get("created_at")
22 if not isinstance(created_at, (int, float)) or created_at <= 0:
23 return f"snapshot manifest has invalid created_at (build {build_id})"
24
25 age_minutes = snapshot_age_minutes(manifest, now_timestamp)
26 if age_minutes > SNAPSHOT_AGE_ALERT_MINUTES:
27 return (
28 f"serving snapshot is {age_minutes:.0f}m old "
29 f"(build {build_id}) - freshness bound exceeded; builder or adoption delayed"
30 )
31 return None