本文整理汇总了Python中stubo.cache.Cache.get_active_sessions方法的典型用法代码示例。如果您正苦于以下问题:Python Cache.get_active_sessions方法的具体用法?Python Cache.get_active_sessions怎么用?Python Cache.get_active_sessions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stubo.cache.Cache
的用法示例。
在下文中一共展示了Cache.get_active_sessions方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete_scenario
# 需要导入模块: from stubo.cache import Cache [as 别名]
# 或者: from stubo.cache.Cache import get_active_sessions [as 别名]
def delete_scenario(scenario_name_key, force):
log.debug(u'delete_scenario: {0}'.format(scenario_name_key))
host, scenario_name = scenario_name_key.split(':')
cache = Cache(host)
if not force:
active_sessions = cache.get_active_sessions(scenario_name,
local=False)
if active_sessions:
raise exception_response(400,
title='Sessons in playback/record, can not delete. Found th'
'e following active sessions: {0} for scenario: {1}'.format(
active_sessions, scenario_name))
scenario_db.remove_all(scenario_name_key)
cache.delete_caches(scenario_name)
示例2: delete
# 需要导入模块: from stubo.cache import Cache [as 别名]
# 或者: from stubo.cache.Cache import get_active_sessions [as 别名]
def delete(self, scenario_name):
"""
Deletes specified scenario. If force is not supplied - checks for active sessions and if there are any - stops
deletion. If force is supplied or there are no active sessions - deletes all stubs for scenario
:param scenario_name:
:return:
"""
response = {
'version': version
}
# checking for supplied headers
host = None
force = False
if 'target_host' in self.request.headers:
host = self.request.headers['target_host']
if 'force' in self.request.headers:
force = asbool(self.request.headers['force'])
# getting full scenario database
scenario_name = _get_scenario_full_name(self, scenario_name, host)
host, scenario = scenario_name.split(':')
cache = Cache(host)
# if force is False or absent - checking for active sessions and if there are any - aborting deletion
if not force:
active_sessions = cache.get_active_sessions(scenario,
local=False)
if active_sessions:
self.set_status(409)
error = 'Sessons in playback/record, can not delete. Found the ' \
'following active sessions: {0} for scenario: {1}'.format(active_sessions, scenario_name)
response['error'] = error
self.write(response)
return
# asynchronous deletion of stubs, returns two params - "ok" and "n" (deleted items count)
result = yield self.db.scenario_stub.remove({'scenario': scenario_name})
# deleting scenario from cache
cache.delete_caches(scenario)
response['data'] = "Deleted stubs count: %s" % result['n']
self.write(response)