Skip to content
Browse files

NEW: added cleaning step for PolicyResultLog in CacheCleanerAgent

  • Loading branch information...
1 parent 3e66f93 commit cc42fc499a6815c9089482013e61c91ebab20b1c @ubeda committed
Showing with 45 additions and 38 deletions.
  1. +45 −38 ResourceStatusSystem/Agent/CacheCleanerAgent.py
View
83 ResourceStatusSystem/Agent/CacheCleanerAgent.py
@@ -61,54 +61,61 @@ def initialize( self ):
def execute( self ):
- try:
+# try:
- # Cleans history tables from entries older than 6 months.
- now = datetime.utcnow().replace( microsecond = 0, second = 0 )
- sixMonthsAgo = now - timedelta( days = 180 )
+ # Cleans history tables from entries older than 6 months.
+ now = datetime.utcnow().replace( microsecond = 0, second = 0 )
+ sixMonthsAgo = now - timedelta( days = 180 )
- for granularity in ValidRes:
- #deleter = getattr( self.rsClient, 'delete%sHistory' % g )
+ for granularity in ValidRes:
+ #deleter = getattr( self.rsClient, 'delete%sHistory' % g )
- kwargs = { 'meta' : { 'minor' : { 'DateEnd' : sixMonthsAgo } } }
- self.log.info( 'Deleting %sHistory older than %s' % ( granularity, sixMonthsAgo ) )
- res = self.rsClient.deleteElementHistory( granularity, **kwargs )
- if not res[ 'OK' ]:
- self.log.error( res[ 'Message' ] )
+ kwargs = { 'meta' : { 'minor' : { 'DateEnd' : sixMonthsAgo } } }
+ self.log.info( 'Deleting %sHistory older than %s' % ( granularity, sixMonthsAgo ) )
+ res = self.rsClient.deleteElementHistory( granularity, **kwargs )
+ if not res[ 'OK' ]:
+ self.log.error( res[ 'Message' ] )
- # Cleans ClientsCache table from DownTimes older than a day.
- aDayAgo = now - timedelta( days = 1 )
+ # Cleans ClientsCache table from DownTimes older than a day.
+ aDayAgo = now - timedelta( days = 1 )
- kwargs = { 'meta' : {
- 'value' : 'EndDate',
- 'columns': 'Opt_ID',
- 'minor' : { 'Result' : str( aDayAgo ) }
- }
- }
- opt_IDs = self.rmClient.getClientCache( **kwargs )
- opt_IDs = [ ID[ 0 ] for ID in opt_IDs[ 'Value' ] ]
+ kwargs = { 'meta' : {
+ 'value' : 'EndDate',
+ 'columns': 'Opt_ID',
+ 'minor' : { 'Result' : str( aDayAgo ) }
+ }
+ }
+ opt_IDs = self.rmClient.getClientCache( **kwargs )
+ opt_IDs = [ ID[ 0 ] for ID in opt_IDs[ 'Value' ] ]
- if opt_IDs:
- self.log.info( 'Found %s ClientCache items to be deleted' % len( opt_IDs) )
- self.log.debug( opt_IDs )
+ if opt_IDs:
+ self.log.info( 'Found %s ClientCache items to be deleted' % len( opt_IDs) )
+ self.log.debug( opt_IDs )
- res = self.rmClient.deleteClientCache( opt_ID = opt_IDs )
- if not res[ 'OK' ]:
- self.log.error( res[ 'Message' ] )
+ res = self.rmClient.deleteClientCache( opt_ID = opt_IDs )
+ if not res[ 'OK' ]:
+ self.log.error( res[ 'Message' ] )
- # Cleans AccountingCache table from plots not updated nor checked in the last 30 mins
- anHourAgo = now - timedelta( minutes = 30 )
- self.log.info( 'Deleting AccountingCache older than %s' % ( anHourAgo ) )
- res = self.rmClient.deleteAccountingCache( meta = {'minor': { 'LastCheckTime' : anHourAgo }} )
- if not res[ 'OK' ]:
- self.log.error( res[ 'Message' ] )
+ # Cleans AccountingCache table from plots not updated nor checked in the last 30 mins
+ anHourAgo = now - timedelta( minutes = 30 )
+ self.log.info( 'Deleting AccountingCache older than %s' % ( anHourAgo ) )
+ res = self.rmClient.deleteAccountingCache( meta = {'minor': { 'LastCheckTime' : anHourAgo }} )
+ if not res[ 'OK' ]:
+ self.log.error( res[ 'Message' ] )
- return S_OK()
+ # Cleans PolicyResultLog
+ twoWeeksAgo = now - timedelta( days = 10 )
+ self.log.info( 'Deleting PolicyResultLog older than %s' % ( twoWeeksAgo ) )
+ res = self.rmClient.deletePolicyResultLog( meta = {'minor': { 'LastCheckTime' : twoWeeksAgo }} )
+ if not res[ 'OK' ]:
+ self.log.error( res[ 'Message' ] )
+
+ return S_OK()
- except Exception:
- errorStr = "CacheCleanerAgent execution"
- self.log.exception( errorStr )
- return S_ERROR( errorStr )
+# except Exception:
+# errorStr = "CacheCleanerAgent execution"
+# self.log.exception( errorStr )
+# return S_ERROR( errorStr )
################################################################################
#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF#EOF

0 comments on commit cc42fc4

Please sign in to comment.
Something went wrong with that request. Please try again.