Skip to content

Commit 3ba2a77

Browse files
committed
getCCDBTimeMachineTimestamp.py: do second CCDB query before uploading new object
1 parent 8c74863 commit 3ba2a77

1 file changed

Lines changed: 20 additions & 13 deletions

File tree

‎GRID/utils/getCCDBTimeMachineTimestamp.py‎

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def query_CCDBTimeMachineTS(base_url, user, period, passname):
211211
Queries CCDBTimeMachineTS from CCDB for a given period and pass.
212212
213213
Returns:
214-
obtained NotAfter timestamp (int) or None
214+
(tuple) (obtained NotAfter timestamp (int), True) or (None, False)
215215
"""
216216
# Construct user ID-specific cert and key paths
217217
cert_path, key_path = make_cert_paths()
@@ -235,9 +235,9 @@ def filter_known_fields(cls, data: dict) -> dict:
235235
print(f"[getCCDBTimeMachineTimestamp] Found object for {clean_meta['Period']}, Pass: {clean_meta['Pass']}, "
236236
f"NotAfter: {clean_meta['NotAfter']} ({human(clean_meta['NotAfter'])}), uploaded by LPMProductionTag {clean_meta['LPMProductionTag']}",
237237
file=sys.stderr)
238-
return clean_meta['NotAfter']
238+
return clean_meta['NotAfter'], True
239239

240-
return None
240+
return None, False
241241

242242

243243
def upload_CCDBTimeMachineTS(base_url, user, keys):
@@ -288,20 +288,27 @@ def get_CCDBTimeMachineTS(production_tag, year, period, run, passname,
288288
Returns:
289289
int: Either the queried or the estimated NotAfter timestamp
290290
"""
291+
found = False
291292
if not skip_ccdb_query:
292-
not_after = query_CCDBTimeMachineTS(ccdb_url, username, period, passname)
293-
else:
294-
not_after = None
293+
not_after, found = query_CCDBTimeMachineTS(ccdb_url, username, period, passname)
295294

296-
if not_after is not None and force_overwrite == True:
297-
print("[getCCDBTimeMachineTimestamp] Existing object will be overwritten", file=sys.stderr)
298-
299-
if not_after == None or force_overwrite == True:
295+
if not found or force_overwrite:
300296
print("[getCCDBTimeMachineTimestamp] Estimating CCDBTimeMachineTS for "
301297
f"LPMProductionTag: {production_tag}, Period: {period}, Pass: {passname}", file=sys.stderr)
302298
not_after = get_NotAfter(year, period, run, passname, samples, ccdb_check_path, ccdb_check)
303-
time_machine_ts = CCDBTimeMachineTS(production_tag, period, passname, not_after)
299+
304300
if publish_to_ccdb:
301+
if not found:
302+
# check again in case another subjob uploaded an object in the meantime
303+
not_after_q, found = query_CCDBTimeMachineTS(ccdb_url, username, period, passname)
304+
305+
if found:
306+
if force_overwrite:
307+
print("[getCCDBTimeMachineTimestamp] Existing object will be overwritten", file=sys.stderr)
308+
else:
309+
return not_after_q
310+
311+
time_machine_ts = CCDBTimeMachineTS(production_tag, period, passname, not_after)
305312
upload_CCDBTimeMachineTS(ccdb_url, username, dataclasses.asdict(time_machine_ts))
306313

307314
return not_after
@@ -335,11 +342,11 @@ def main():
335342
help="overwrite the current CCDBTimeMachineTS object in the CCDB if one exists")
336343
parser.add_argument("--ccdb-url", default="https://alice-ccdb.cern.ch",
337344
help="ccdb host for the upload")
338-
parser.add_argument("--username", default="aliprod",
345+
parser.add_argument("--username", default=os.environ.get("JALIEN_USER"),
339346
help="username to be used for the upload to CCDB")
340347
args = parser.parse_args()
341348

342-
missing = [n for n in ("year", "period", "run", "passname") if not getattr(args, n)]
349+
missing = [n for n in ("production_tag", "year", "period", "run", "passname", "username") if not getattr(args, n)]
343350
if missing:
344351
parser.error("missing required value(s): " + ", ".join(missing))
345352

0 commit comments

Comments
 (0)