本文整理汇总了Python中st2common.persistence.trigger.TriggerInstance.query方法的典型用法代码示例。如果您正苦于以下问题:Python TriggerInstance.query方法的具体用法?Python TriggerInstance.query怎么用?Python TriggerInstance.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类st2common.persistence.trigger.TriggerInstance
的用法示例。
在下文中一共展示了TriggerInstance.query方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: purge_trigger_instances
# 需要导入模块: from st2common.persistence.trigger import TriggerInstance [as 别名]
# 或者: from st2common.persistence.trigger.TriggerInstance import query [as 别名]
def purge_trigger_instances(timestamp=None):
if not timestamp:
LOG.error('Specify a valid timestamp to purge.')
return
LOG.info('Purging trigger instances older than timestamp: %s' %
timestamp.strftime('%Y-%m-%dT%H:%M:%S.%fZ'))
# XXX: Think about paginating this call.
filters = {'occurrence_time__lt': isotime.parse(timestamp)}
instances = TriggerInstance.query(**filters)
LOG.info('#### Total number of trigger instances to delete: %d' % len(instances))
# Purge execution and liveaction models now
for instance in instances:
_purge_model(instance)
# Print stats
LOG.info('#### Total trigger instances deleted: %d' % DELETED_COUNT)
示例2: _append_view_properties
# 需要导入模块: from st2common.persistence.trigger import TriggerInstance [as 别名]
# 或者: from st2common.persistence.trigger.TriggerInstance import query [as 别名]
def _append_view_properties(self, rule_enforcement_apis):
"""
Method which appends corresponding execution (if available) and trigger instance object
properties.
"""
trigger_instance_ids = set([])
execution_ids = []
for rule_enforcement_api in rule_enforcement_apis:
if rule_enforcement_api.get('trigger_instance_id', None):
trigger_instance_ids.add(str(rule_enforcement_api['trigger_instance_id']))
if rule_enforcement_api.get('execution_id', None):
execution_ids.append(rule_enforcement_api['execution_id'])
# 1. Retrieve corresponding execution objects
# NOTE: Executions contain a lot of field and could contain a lot of data so we only
# retrieve fields we need
only_fields = [
'id',
'action.ref',
'action.parameters',
'runner.name',
'runner.runner_parameters',
'parameters',
'status'
]
execution_dbs = ActionExecution.query(id__in=execution_ids,
only_fields=only_fields)
execution_dbs_by_id = {}
for execution_db in execution_dbs:
execution_dbs_by_id[str(execution_db.id)] = execution_db
# 2. Retrieve corresponding trigger instance objects
trigger_instance_dbs = TriggerInstance.query(id__in=list(trigger_instance_ids))
trigger_instance_dbs_by_id = {}
for trigger_instance_db in trigger_instance_dbs:
trigger_instance_dbs_by_id[str(trigger_instance_db.id)] = trigger_instance_db
# Ammend rule enforcement objects with additional data
for rule_enforcement_api in rule_enforcement_apis:
rule_enforcement_api['trigger_instance'] = {}
rule_enforcement_api['execution'] = {}
trigger_instance_id = rule_enforcement_api.get('trigger_instance_id', None)
execution_id = rule_enforcement_api.get('execution_id', None)
trigger_instance_db = trigger_instance_dbs_by_id.get(trigger_instance_id, None)
execution_db = execution_dbs_by_id.get(execution_id, None)
if trigger_instance_db:
trigger_instance_api = TriggerInstanceAPI.from_model(trigger_instance_db)
rule_enforcement_api['trigger_instance'] = trigger_instance_api
if execution_db:
execution_api = ActionExecutionAPI.from_model(execution_db)
rule_enforcement_api['execution'] = execution_api
return rule_enforcement_apis