From cb6d67dd370f64cd7907412e077ff8ab6e09abc3 Mon Sep 17 00:00:00 2001 From: Dannon Baker Date: Sun, 31 May 2026 13:50:35 -0400 Subject: [PATCH] Extract _download_manifest to dedupe the IWC fetch block fetch_manifest and refresh_manifest both had a byte-identical fetch/raise_for_status/json/isinstance block. Pull it into a private helper so the two functions differ only in their locking strategy -- which is the actual point refresh_manifest's docstring labors to explain. --- lib/galaxy/agents/iwc.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/lib/galaxy/agents/iwc.py b/lib/galaxy/agents/iwc.py index 14a1c6e7b12..cc5386aa77f 100644 --- a/lib/galaxy/agents/iwc.py +++ b/lib/galaxy/agents/iwc.py @@ -33,6 +33,16 @@ def clear_manifest_cache() -> None: _manifest_cache.clear() +def _download_manifest(timeout: float) -> list[dict[str, Any]]: + """Fetch and validate the IWC manifest over the network, bypassing the cache.""" + response = requests.get(IWC_MANIFEST_URL, timeout=timeout) + response.raise_for_status() + manifest = response.json() + if not isinstance(manifest, list): + raise ValueError(f"IWC manifest at {IWC_MANIFEST_URL} did not return a JSON array") + return manifest + + def fetch_manifest(timeout: float = 30.0) -> list[dict[str, Any]]: """Fetch the IWC manifest, returning a cached copy when fresh. @@ -44,11 +54,7 @@ def fetch_manifest(timeout: float = 30.0) -> list[dict[str, Any]]: if cached is not None: return cached - response = requests.get(IWC_MANIFEST_URL, timeout=timeout) - response.raise_for_status() - manifest = response.json() - if not isinstance(manifest, list): - raise ValueError(f"IWC manifest at {IWC_MANIFEST_URL} did not return a JSON array") + manifest = _download_manifest(timeout) _manifest_cache[_CACHE_KEY] = manifest return manifest @@ -66,11 +72,7 @@ def refresh_manifest(timeout: float = 30.0) -> list[dict[str, Any]]: continue without the data); this one is called from a periodic task that has to tolerate transient failure. """ - response = requests.get(IWC_MANIFEST_URL, timeout=timeout) - response.raise_for_status() - manifest = response.json() - if not isinstance(manifest, list): - raise ValueError(f"IWC manifest at {IWC_MANIFEST_URL} did not return a JSON array") + manifest = _download_manifest(timeout) with _manifest_cache_lock: _manifest_cache[_CACHE_KEY] = manifest return manifest