refactor: one etag probe for buildbot and refresh

The buildbot check now waits 30 s like the refresh, not 15.
This commit is contained in:
Abdessamad Derraz committed 2026-11-21 06:00:31 +01:00
1 parent 85f60ec525
commit 95ed63a3f3
3 files changed
+15 -27

No files matched your search

+13
View File
@@ -419,6 +419,19 @@ def http_text(url: str) -> str | None:
return None if body is None else body.decode("utf-8", errors="replace")
def remote_etag(url: str, timeout: float = 30) -> str | None:
"""ETag, else Last-Modified, of a HEAD; "" when neither is sent, None
when the server does not answer."""
req = urllib.request.Request(
url, method="HEAD", headers=forge_headers(url, user_agent="retrobios/1.0")
)
try:
with urllib.request.urlopen(req, timeout=timeout) as resp:
return resp.headers.get("ETag") or resp.headers.get("Last-Modified") or ""
except (urllib.error.URLError, OSError):
return None
def http_json(url: str) -> object | None:
"""Parsed JSON body of a GET, or None on 404. Replaced in tests."""
body = fetch_body(url, accept_json=True)
+1 -12
View File
@@ -17,6 +17,7 @@ from pathlib import Path
from core.artifacts import file_lock as _file_lock, write_text_atomic
from core.github import github_token
from core.upstream import remote_etag as _get_remote_etag
from model.registry import VERSIONS_FILE, load_versions
@@ -434,18 +435,6 @@ def _record_archive_size(key: str, entry: dict, versions_path: str) -> None:
log.info("[%s] archive size recorded: %d bytes", key, size)
def _get_remote_etag(source_url: str) -> str | None:
"""HEAD request to get ETag or Last-Modified for freshness check."""
try:
req = urllib.request.Request(
source_url, method="HEAD", headers={"User-Agent": USER_AGENT}
)
with urllib.request.urlopen(req, timeout=REQUEST_TIMEOUT) as resp:
return resp.headers.get("ETag") or resp.headers.get("Last-Modified") or ""
except (urllib.error.URLError, OSError):
return None
def _short_tag(tag: str | None) -> str:
"""A commit sha or ETag cut for a log line, quotes dropped first: a
quoted ETag cut at 12 characters kept its opening quote only."""
+1 -15
View File
@@ -7,8 +7,8 @@ import subprocess
import sys
import urllib.error
import urllib.parse
import urllib.request
from core.upstream import remote_etag as get_remote_etag
from model.registry import data_dir_registry_at, load_versions
from .base_scraper import fetch_text
@@ -17,8 +17,6 @@ log = logging.getLogger(__name__)
BUILDBOT_SYSTEM_URL = "https://buildbot.libretro.com/assets/system/"
INDEX_URL = BUILDBOT_SYSTEM_URL + ".index"
USER_AGENT = "retrobios/1.0"
REQUEST_TIMEOUT = 15
DEFAULT_REGISTRY = "platforms/_data_dirs.yml"
@@ -45,18 +43,6 @@ def load_tracked_entries(
return entries
def get_remote_etag(url: str) -> str | None:
"""HEAD request to get ETag."""
try:
req = urllib.request.Request(
url, method="HEAD", headers={"User-Agent": USER_AGENT}
)
with urllib.request.urlopen(req, timeout=REQUEST_TIMEOUT) as resp:
return resp.headers.get("ETag") or resp.headers.get("Last-Modified") or ""
except (urllib.error.URLError, OSError):
return None
def check(registry_path: str = DEFAULT_REGISTRY) -> dict:
"""Run the buildbot check. Returns structured report."""
try: