Skip to content
25 changes: 25 additions & 0 deletions pandajedi/jedidog/AtlasDataCarouselWatchDog.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
StageDCRequests_LOCK_TIME_MINUTES = 5
CheckDCRequests_LOCK_TIME_MINUTES = 5
KeepRulesAlive_LOCK_TIME_MINUTES = 60
UpdateRequestsUsage_LOCK_TIME_MINUTES = 480
CleanDCRequests_LOCK_TIME_MINUTES = 1440
RescuePendingTasks_LOCK_TIME_MINUTES = 120

Expand Down Expand Up @@ -123,6 +124,28 @@ def doKeepRulesAlive(self) -> None:
errtype, errvalue = sys.exc_info()[:2]
tmpLog.error(f"failed with {errtype} {errvalue} {traceback.format_exc()}")

def doUpdateRequestsUsage(self) -> None:
"""
Action to update the usage of DC requests (remove_when_done and last_used_time) according to their related tasks,
and keep alive DDM rules of done requests within grace period after last used
"""
tmpLog = MsgWrapper(logger, " #ATM #KV doUpdateRequestsUsage")
tmpLog.debug("start")
try:
# watchdog lock
got_lock = self.get_process_lock("AtlasDataCarousDog.doUpdateReqUsage", timeLimit=UpdateRequestsUsage_LOCK_TIME_MINUTES)
if not got_lock:
tmpLog.debug("locked by another watchdog process. Skipped")
return
tmpLog.debug("got watchdog lock")
# update usage of requests
self.data_carousel_interface.update_requests_usage()
# done
tmpLog.debug("done")
except Exception:
errtype, errvalue = sys.exc_info()[:2]
tmpLog.error(f"failed with {errtype} {errvalue} {traceback.format_exc()}")

def doCleanDCRequests(self) -> None:
"""
Action to clean up old DC requests in DB table
Expand Down Expand Up @@ -171,6 +194,8 @@ def doAction(self) -> Interaction.StatusCode:
# get logger
origTmpLog = MsgWrapper(logger)
origTmpLog.debug("start")
# update usage of DC requests before cleaning them up
self.doUpdateRequestsUsage()
# clean up old DC requests
self.doCleanDCRequests()
# keep staging rules alive
Expand Down
Loading