Skip to content

Commit b34b81c

Browse files
authored
[QC-1144] 1_per_run : Consider RunNumber=0 as no run number (#2238)
1 parent 9630586 commit b34b81c

1 file changed

Lines changed: 15 additions & 15 deletions

File tree

  • Framework/script/RepoCleaner/qcrepocleaner/rules

Framework/script/RepoCleaner/qcrepocleaner/rules/1_per_run.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,23 @@
1111
logger = logging # default logger
1212

1313

14-
def process(ccdb: Ccdb, object_path: str, delay: int, from_timestamp: int, to_timestamp: int, extra_params: Dict[str, str]):
15-
'''
14+
def process(ccdb: Ccdb, object_path: str, delay: int, from_timestamp: int, to_timestamp: int,
15+
extra_params: Dict[str, str]):
16+
"""
1617
Process this deletion rule on the object. We use the CCDB passed by argument.
1718
Objects which have been created recently are spared (delay is expressed in minutes).
1819
This specific policy, 1_per_run, keeps only the most recent version for a given run based on the createdAt.
1920
2021
Config Parameters:
2122
- period_pass: Keep 1 version for a combination of run+pass+period if true.
2223
- delete_when_no_run: Versions without runs are preserved if delete_when_no_run is set to false (default).
23-
Otherwise only the last one is preserved.
24+
Otherwise, only the last one is preserved.
2425
THEY CANNOT BE BOTH TRUE AT THE SAME TIME
2526
2627
It is implemented like this :
2728
Map of buckets: run[+pass+period] -> list of versions
2829
Go through all objects: Add the object to the corresponding key (run[+pass+period])
29-
If delete_when_no_run is false, remove the versions without run from the map
30+
If delete_when_no_run is false, remove from the map the versions without run or with run==0
3031
Go through the map: for each run (resp. run+pass+period) keep the most recent object and delete the rest.
3132
3233
:param ccdb: the ccdb in which objects are cleaned up.
@@ -36,8 +37,8 @@ def process(ccdb: Ccdb, object_path: str, delay: int, from_timestamp: int, to_t
3637
:param to_timestamp: only objects created before this timestamp are considered.
3738
:param extra_params: a dictionary containing extra parameters for this rule.
3839
:return a dictionary with the number of deleted, preserved and updated versions. Total = deleted+preserved.
39-
'''
40-
40+
"""
41+
4142
logger.debug(f"Plugin 1_per_run processing {object_path}")
4243

4344
preservation_list: List[ObjectVersion] = []
@@ -46,11 +47,11 @@ def process(ccdb: Ccdb, object_path: str, delay: int, from_timestamp: int, to_t
4647
versions_buckets_dict: DefaultDict[str, List[ObjectVersion]] = defaultdict(list)
4748

4849
# config parameters
49-
delete_when_no_run = (extra_params.get("delete_when_no_run", False) == True)
50+
delete_when_no_run = (extra_params.get("delete_when_no_run", False) is True)
5051
logger.debug(f"delete_when_no_run : {delete_when_no_run}")
51-
period_pass = (extra_params.get("period_pass", False) == True)
52+
period_pass = (extra_params.get("period_pass", False) is True)
5253
logger.debug(f"period_pass : {period_pass}")
53-
if delete_when_no_run == True and period_pass == True:
54+
if delete_when_no_run is True and period_pass is True:
5455
logger.error(f"1_per_run does not allow both delete_when_no_run and period_pass to be on at the same time")
5556
return {"deleted": 0, "preserved": 0, "updated": 0}
5657

@@ -64,6 +65,7 @@ def process(ccdb: Ccdb, object_path: str, delay: int, from_timestamp: int, to_t
6465
# if we should not touch the files with no runs, let's just remove them from the map
6566
if not delete_when_no_run:
6667
del versions_buckets_dict['none']
68+
del versions_buckets_dict['0']
6769

6870
# Dispatch the versions to deletion and preservation lists
6971
for bucket, run_versions in versions_buckets_dict.items():
@@ -92,10 +94,10 @@ def process(ccdb: Ccdb, object_path: str, delay: int, from_timestamp: int, to_t
9294
temp_deletion_list: List[ObjectVersion] = []
9395
for v in deletion_list:
9496
if from_timestamp < v.validFrom < to_timestamp: # in the allowed period
95-
temp_deletion_list.append(v) # we will delete any ways
97+
temp_deletion_list.append(v) # we will delete any ways
9698
ccdb.deleteVersion(v)
9799
else:
98-
preservation_list.append(v) # we preserve
100+
preservation_list.append(v) # we preserve
99101
deletion_list = temp_deletion_list
100102

101103
logger.debug(f"deleted ({len(deletion_list)}) : ")
@@ -110,14 +112,12 @@ def process(ccdb: Ccdb, object_path: str, delay: int, from_timestamp: int, to_t
110112
for v in update_list:
111113
logger.debug(f" {v}")
112114

113-
return {"deleted" : len(deletion_list), "preserved": len(preservation_list), "updated" : len(update_list)}
114-
115-
115+
return {"deleted": len(deletion_list), "preserved": len(preservation_list), "updated": len(update_list)}
116116

117117

118118
def main():
119119
logger.getLogger().setLevel(int(10))
120-
dryable.set( True )
120+
dryable.set(True)
121121
ccdb = Ccdb('http://ccdb-test.cern.ch:8080')
122122
process(ccdb, "qc/testRunCleanup", 0)
123123

0 commit comments

Comments
 (0)