mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
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.
This commit is contained in:
+12
-10
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user