Skip to content

Commit 0a11ae4

Browse files
committed
getCCDBTimeMachineTimestamp.py: make CCDB cross-check non-fatal
1 parent 8e09c7b commit 0a11ae4

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

‎GRID/utils/getCCDBTimeMachineTimestamp.py‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,30 +113,35 @@ def get_ccdb_objects(url, timeout = 15):
113113
with urllib.request.urlopen(req, timeout=timeout) as resp:
114114
data = json.load(resp)
115115
except Exception as exc:
116-
return {"error": str(exc)}
116+
print_warning(f"Request to {url} failed: {exc}")
117+
return None
117118

118-
objects = data.get("objects", [])
119-
return objects
119+
return data.get("objects", []) if isinstance(data, dict) else None
120120

121121

122122
def get_run_start_tf(run):
123123
run_info_url = f"{CCDB_HOST}/browse/RCT/Info/RunInformation/{run}"
124124
objects = get_ccdb_objects(run_info_url)
125125

126-
return objects[0]["STF"]
126+
return objects[0].get("STF", 0) if objects else None
127127

128128

129129
def ccdb_cross_check(run, path, not_after):
130130
"""Report which object a correctly time-machine-pinned query at not_after
131131
would actually resolve to, and flag if CCDB has since been updated for the
132-
same validity window. Never raises; returns None on any failure."""
132+
same validity window. Never raises."""
133133
timestamp = get_run_start_tf(run)
134+
if not timestamp:
135+
print_warning(f"CCDB cross-check on {path} skipped: "
136+
"failed to obtain run start timestamp")
137+
return
138+
134139
url = f"{CCDB_HOST}/browse/{path}/{timestamp}"
135140

136141
objects = get_ccdb_objects(url)
137142
if not objects:
138143
print_warning(f"CCDB cross-check on {path}/{timestamp} skipped: "
139-
"no CCDB object covers this instant")
144+
f"{'CCDB request failed' if objects is None else 'no CCDB object covers this instant'}")
140145
return
141146

142147
as_of_candidates = [o for o in objects if o.get("Created", 0) <= not_after]
@@ -363,7 +368,10 @@ def main():
363368
args.samples, args.ccdb_url, args.username,
364369
args.force_overwrite, args.publish_to_ccdb, args.skip_ccdb_query)
365370
if not args.no_ccdb_check:
366-
ccdb_cross_check(args.run, args.ccdb_check_path, not_after)
371+
try:
372+
ccdb_cross_check(args.run, args.ccdb_check_path, not_after)
373+
except Exception as exc:
374+
print_warning(f"CCDB cross-check failed with unforeseen exception: {exc}")
367375

368376
print(not_after)
369377

0 commit comments

Comments
 (0)