Skip to content

Commit 99a766c

Browse files
committed
fix: no need for purging the expired
1 parent e5259ad commit 99a766c

File tree

3 files changed

+32
-26
lines changed

3 files changed

+32
-26
lines changed

src/DIRAC/Core/Utilities/DictCache.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ class MockLockRing:
2727

2828
def doNothing(self, *args, **kwargs):
2929
"""Really does nothing !"""
30-
pass
3130

3231
acquire = release = doNothing
3332

@@ -105,9 +104,9 @@ def exists(self, cKey, validSeconds=0):
105104
# If it's valid return True!
106105
if expTime > datetime.datetime.now() + datetime.timedelta(seconds=validSeconds):
107106
return True
108-
else:
109-
# Delete expired
110-
self.delete(cKey)
107+
108+
# Delete expired
109+
self.delete(cKey)
111110
return False
112111
finally:
113112
self.lock.release()
@@ -159,9 +158,9 @@ def get(self, cKey, validSeconds=0):
159158
# If it's valid return True!
160159
if expTime > datetime.datetime.now() + datetime.timedelta(seconds=validSeconds):
161160
return self.__cache[cKey]["value"]
162-
else:
163-
# Delete expired
164-
self.delete(cKey)
161+
162+
# Delete expired
163+
self.delete(cKey)
165164
return None
166165
finally:
167166
self.lock.release()
@@ -174,11 +173,11 @@ def showContentsInString(self):
174173
self.lock.acquire()
175174
try:
176175
data = []
177-
for cKey in self.__cache:
178-
data.append("%s:" % str(cKey))
179-
data.append("\tExp: %s" % self.__cache[cKey]["expirationTime"])
180-
if self.__cache[cKey]["value"]:
181-
data.append("\tVal: %s" % self.__cache[cKey]["value"])
176+
for cKey, cValue in self.__cache.items():
177+
data.append(f"{cKey}:")
178+
data.append(f"\tExp: {cValue['expirationTime']}")
179+
if cValue["value"]:
180+
data.append(f"\tVal: {cValue['Value']}")
182181
return "\n".join(data)
183182
finally:
184183
self.lock.release()
@@ -194,8 +193,8 @@ def getKeys(self, validSeconds=0):
194193
try:
195194
keys = []
196195
limitTime = datetime.datetime.now() + datetime.timedelta(seconds=validSeconds)
197-
for cKey in self.__cache:
198-
if self.__cache[cKey]["expirationTime"] > limitTime:
196+
for cKey, cValue in self.__cache.items():
197+
if cValue["expirationTime"] > limitTime:
199198
keys.append(cKey)
200199
return keys
201200
finally:
@@ -210,13 +209,13 @@ def purgeExpired(self, expiredInSeconds=0):
210209
try:
211210
keys = []
212211
limitTime = datetime.datetime.now() + datetime.timedelta(seconds=expiredInSeconds)
213-
for cKey in self.__cache:
214-
if self.__cache[cKey]["expirationTime"] < limitTime:
212+
for cKey, cValue in self.__cache.items():
213+
if cValue["expirationTime"] < limitTime:
215214
keys.append(cKey)
216-
for cKey in keys:
215+
for key in keys:
217216
if self.__deleteFunction:
218-
self.__deleteFunction(self.__cache[cKey]["value"])
219-
del self.__cache[cKey]
217+
self.__deleteFunction(self.__cache[key]["value"])
218+
del self.__cache[key]
220219
finally:
221220
self.lock.release()
222221

src/DIRAC/FrameworkSystem/Service/BundleDeliveryHandler.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,15 @@ def updateBundles(self):
8383
class BundleDeliveryHandlerMixin:
8484
@classmethod
8585
def initializeHandler(cls, serviceInfoDict):
86+
87+
## FIXME: move to an agent
8688
csPath = serviceInfoDict["serviceSectionPath"]
8789
cls.bundleManager = BundleManager(csPath)
8890
updateBundleTime = gConfig.getValue("%s/BundlesLifeTime" % csPath, 3600 * 6)
8991
gLogger.info("Bundles will be updated each %s secs" % updateBundleTime)
9092
gThreadScheduler.addPeriodicTask(updateBundleTime, cls.bundleManager.updateBundles)
93+
##
94+
9195
return S_OK()
9296

9397
types_getListOfBundles = []

src/DIRAC/FrameworkSystem/Service/NotificationHandler.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,28 @@
1212
It can also be used to set alarms to be promptly forwarded to those
1313
subscribing to them.
1414
"""
15-
from DIRAC import gConfig, S_OK, S_ERROR
16-
15+
from DIRAC import S_ERROR, S_OK, gConfig
16+
from DIRAC.ConfigurationSystem.Client import PathFinder
1717
from DIRAC.Core.DISET.RequestHandler import RequestHandler
18+
from DIRAC.Core.Security import Properties
19+
from DIRAC.Core.Utilities.DictCache import DictCache
1820
from DIRAC.Core.Utilities.Mail import Mail
1921
from DIRAC.Core.Utilities.ThreadScheduler import gThreadScheduler
20-
from DIRAC.Core.Security import Properties
21-
from DIRAC.ConfigurationSystem.Client import PathFinder
2222
from DIRAC.FrameworkSystem.DB.NotificationDB import NotificationDB
23-
from DIRAC.Core.Utilities.DictCache import DictCache
2423

2524

2625
class NotificationHandlerMixin:
2726
@classmethod
2827
def initializeHandler(cls, serviceInfo):
2928
"""Handler initialization"""
30-
cls.notDB = NotificationDB()
29+
3130
cls.mailCache = DictCache()
31+
cls.notDB = NotificationDB()
32+
33+
## FIXME: move to an agent
3234
gThreadScheduler.addPeriodicTask(3600, cls.notDB.purgeExpiredNotifications)
33-
gThreadScheduler.addPeriodicTask(3600, cls.mailCache.purgeExpired())
35+
##
36+
3437
return S_OK()
3538

3639
def initialize(self):

0 commit comments

Comments
 (0)