Skip to content

Commit f02689a

Browse files
TypingKoalaJohnny Bui
andauthored
Fix HydraFetcher download of meta.json files (#17)
* Update tests for hydrafetcher * implement fix for meta.json download failures * added additional comments * Make error handling messages more verbose Co-authored-by: Johnny Bui <[email protected]>
1 parent 2c06f09 commit f02689a

File tree

5 files changed

+983
-20
lines changed

5 files changed

+983
-20
lines changed

ftpvl/fetchers.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,17 +114,47 @@ def _download(self) -> List[Dict]:
114114
raise IndexError(f"Invalid eval_num: {self.eval_num}")
115115
build_nums = evals_json["evals"][self.eval_num]["builds"]
116116

117-
# collect the 'meta.json' build products
117+
# fetch build info and download 'meta.json'
118118
data = []
119119
for build_num in build_nums:
120+
# get build info
120121
resp = requests.get(
121-
f"https://hydra.vtr.tools/build/{build_num}/download/1/meta.json",
122+
f"https://hydra.vtr.tools/build/{build_num}",
123+
headers={"Content-Type": "application/json"},
124+
)
125+
if resp.status_code != 200:
126+
raise Exception(f"Unable to get build {build_num}, got status code {resp.status_code}.")
127+
128+
decoded = None
129+
try:
130+
decoded = resp.json()
131+
except json.decoder.JSONDecodeError as err:
132+
raise Exception(f"Unable to decode build {build_num} JSON file, {str(err)}")
133+
134+
# check if build was successful
135+
if decoded.get("buildstatus") != 0:
136+
print(f"Warning: Build {build_num} failed with non-zero exit. Skipping...")
137+
continue
138+
139+
# check if meta.json exists
140+
meta_json_id = None
141+
for product_id, product_desc in decoded.get("buildproducts", {}).items():
142+
if product_desc.get("name", "") == "meta.json":
143+
meta_json_id = product_id
144+
145+
if meta_json_id is None:
146+
print(f"Warning: Build {build_num} does not contain meta.json file. Skipping...")
147+
continue
148+
149+
# download meta.json
150+
resp = requests.get(
151+
f"https://hydra.vtr.tools/build/{build_num}/download/{meta_json_id}/meta.json",
122152
headers={"Content-Type": "application/json"},
123153
)
124154
if resp.status_code != 200:
125155
print(
126156
"Warning:",
127-
f"Unable to get build {build_num}. It might have failed.",
157+
f"Unable to get build {build_num} meta.json file.",
128158
)
129159
continue
130160
try:

0 commit comments

Comments
 (0)