44
55from Ccdb import Ccdb , ObjectVersion
66
7+
78def process (ccdb : Ccdb , object_path : str , delay : int ):
89 '''
910 Process this deletion rule on the object. We use the CCDB passed by argument.
@@ -15,6 +16,7 @@ def process(ccdb: Ccdb, object_path: str, delay: int):
1516 :param ccdb: the ccdb in which objects are cleaned up.
1617 :param object_path: path to the object, or pattern, to which a rule will apply.
1718 :param delay: the grace period during which a new object is never deleted.
19+ :return a dictionary with the number of deleted, preserved and updated versions. Total = deleted+preserved.
1820 '''
1921
2022 logging .debug (f"Plugin 1_per_hour processing { object_path } " )
@@ -24,11 +26,13 @@ def process(ccdb: Ccdb, object_path: str, delay: int):
2426 last_preserved : ObjectVersion = None
2527 preservation_list : List [ObjectVersion ] = []
2628 deletion_list : List [ObjectVersion ] = []
29+ update_list : List [ObjectVersion ] = []
2730 for v in versions :
2831 if last_preserved == None or last_preserved .validFromAsDatetime < v .validFromAsDatetime - timedelta (hours = 1 ):
2932 # first extend validity of the previous preserved (should we take into account the run ?)
3033 if last_preserved != None :
3134 ccdb .updateValidity (last_preserved , last_preserved .validFrom , str (int (v .validFrom ) - 1 ))
35+ update_list .append (last_preserved )
3236 last_preserved = v
3337 preservation_list .append (v )
3438 else :
@@ -45,9 +49,17 @@ def process(ccdb: Ccdb, object_path: str, delay: int):
4549 for v in preservation_list :
4650 logging .debug (f" { v } " )
4751
52+ logging .debug ("updated : " )
53+ for v in update_list :
54+ logging .debug (f" { v } " )
55+
56+ return {"deleted" : len (deletion_list ), "preserved" : len (preservation_list ), "updated" : len (update_list )}
57+
58+
4859def main ():
4960 ccdb = Ccdb ('http://ccdb-test.cern.ch:8080' )
5061 process (ccdb , "asdfasdf/example" , 60 )
5162
52- if __name__ == "__main__" : # to be able to run the test code above when not imported.
63+
64+ if __name__ == "__main__" : # to be able to run the test code above when not imported.
5365 main ()
0 commit comments