本文整理汇总了Python中DIRAC.ResourceStatusSystem.Client.ResourceManagementClient.ResourceManagementClient.deleteAccountingCache方法的典型用法代码示例。如果您正苦于以下问题:Python ResourceManagementClient.deleteAccountingCache方法的具体用法?Python ResourceManagementClient.deleteAccountingCache怎么用?Python ResourceManagementClient.deleteAccountingCache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DIRAC.ResourceStatusSystem.Client.ResourceManagementClient.ResourceManagementClient
的用法示例。
在下文中一共展示了ResourceManagementClient.deleteAccountingCache方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: CacheCleanerAgent
# 需要导入模块: from DIRAC.ResourceStatusSystem.Client.ResourceManagementClient import ResourceManagementClient [as 别名]
# 或者: from DIRAC.ResourceStatusSystem.Client.ResourceManagementClient.ResourceManagementClient import deleteAccountingCache [as 别名]
class CacheCleanerAgent( AgentModule ):
'''
The CacheCleanerAgent tidies up the ResourceStatusDB, namely:
o SiteHistory
o ServiceHistory
o ResourceHistory
o StorageElementHistory
older than 6 months.
It also takes care of the ResourceManagementDB, more specifically:
o ClientCache
o AccountingCache
older than 24 hours for the first one, and 30 minutes for the second one.
If you want to know more about the CacheCleanerAgent, scroll down to the end of the
file.
'''
# Too many public methods
# pylint: disable-msg=R0904
def initialize( self ):
# Attribute defined outside __init__
# pylint: disable-msg=W0201
try:
self.rsClient = ResourceStatusClient()
self.rmClient = ResourceManagementClient()
validElements = RssConfiguration.getValidElements()
self.historyTables = [ '%sHistory' % x for x in validElements ]
return S_OK()
except Exception:
errorStr = "CacheCleanerAgent initialization"
self.log.exception( errorStr )
return S_ERROR( errorStr )
################################################################################
################################################################################
def execute( self ):
# try:
# Cleans history tables from entries older than 6 months.
now = datetime.utcnow().replace( microsecond = 0, second = 0 )
sixMonthsAgo = now - timedelta( days = 180 )
validElements = RssConfiguration.getValidElements()
for granularity in validElements:
#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' ] )
# 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' ] ]
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' ] )
# 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 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()