@@ -68,11 +68,7 @@ def human(ts_ms):
6868 return datetime .fromtimestamp (ts_ms / 1000 , tz = timezone .utc ).strftime ("%Y-%m-%d %H:%M:%S UTC" )
6969
7070
71- def ccdb_cross_check (path , not_after , timeout = 15 ):
72- """Report which object a correctly time-machine-pinned query at not_after
73- would actually resolve to, and flag if CCDB has since been updated for the
74- same validity window. Never raises; returns None on any failure."""
75- url = f"{ CCDB_HOST } /browse/{ path } /{ not_after } "
71+ def get_ccdb_objects (url , timeout = 15 ):
7672 req = urllib .request .Request (url , headers = {"Accept" : "application/json" })
7773 try :
7874 with urllib .request .urlopen (req , timeout = timeout ) as resp :
@@ -81,14 +77,33 @@ def ccdb_cross_check(path, not_after, timeout=15):
8177 return {"error" : str (exc )}
8278
8379 objects = data .get ("objects" , [])
80+ return objects
81+
82+
83+ def get_run_start_tf (run ):
84+ run_info_url = f"{ CCDB_HOST } /browse/RCT/Info/RunInformation/{ run } "
85+ objects = get_ccdb_objects (run_info_url )
86+
87+ return objects [0 ]["STF" ]
88+
89+
90+ def ccdb_cross_check (run , path , not_after , timeout = 15 ):
91+ """Report which object a correctly time-machine-pinned query at not_after
92+ would actually resolve to, and flag if CCDB has since been updated for the
93+ same validity window. Never raises; returns None on any failure."""
94+ timestamp = get_run_start_tf (run )
95+ url = f"{ CCDB_HOST } /browse/{ path } /{ timestamp } "
96+ objects = get_ccdb_objects (url )
8497 if not objects :
8598 return {"error" : "no CCDB object covers this instant" }
8699
87100 as_of = [o for o in objects if o .get ("Created" , 0 ) <= not_after ]
88101 newest = max (objects , key = lambda o : o .get ("Created" , 0 ))
89- pinned = max (as_of , key = lambda o : o .get ("Created" , 0 )) if as_of else None
90- outdated = pinned is not None and newest ["Created" ] > pinned ["Created" ]
91- return {"newest" : newest , "as_of" : pinned , "outdated" : outdated }
102+ result = {"timestamp" : timestamp , "newest" : newest , "as_of" : None , "outdated" : False }
103+ if as_of :
104+ result ["as_of" ] = max (as_of , key = lambda o : o .get ("Created" , 0 ))
105+ result ["outdated" ] = newest ["Created" ] > result ["as_of" ]["Created" ]
106+ return result
92107
93108
94109def describe_object (o ):
@@ -126,17 +141,17 @@ def get_CCDBTimeMachineTS(year, period, run, passname, samples=9, ccdb_check_pat
126141 file = sys .stderr )
127142
128143 if ccdb_check :
129- check = ccdb_cross_check (ccdb_check_path , not_after )
144+ check = ccdb_cross_check (run , ccdb_check_path , not_after )
130145 if check is None or "error" in check :
131146 reason = check ["error" ] if check else "unknown error"
132- print (f"[getCCDBTimeMachineTimestamp] CCDB cross-check on { ccdb_check_path } skipped: { reason } " ,
147+ print (f"[getCCDBTimeMachineTimestamp] CCDB cross-check on { ccdb_check_path } / { check [ "timestamp" ] } skipped: { reason } " ,
133148 file = sys .stderr )
134149 elif check ["as_of" ] is None :
135- print (f"[getCCDBTimeMachineTimestamp] CCDB cross-check on { ccdb_check_path } : no object "
150+ print (f"[getCCDBTimeMachineTimestamp] CCDB cross-check on { ccdb_check_path } / { check [ "timestamp" ] } : no object "
136151 f"existed yet at the recommended timestamp (earliest is { describe_object (check ['newest' ])} )" ,
137152 file = sys .stderr )
138153 else :
139- print (f"[getCCDBTimeMachineTimestamp] CCDB cross-check on { ccdb_check_path } : as-of object is "
154+ print (f"[getCCDBTimeMachineTimestamp] CCDB cross-check on { ccdb_check_path } / { check [ "timestamp" ] } : as-of object is "
140155 f"{ describe_object (check ['as_of' ])} " , file = sys .stderr )
141156 if check ["outdated" ]:
142157 print (f"[getCCDBTimeMachineTimestamp] note: CCDB's current object for this window is newer "
0 commit comments