当前位置: 首页>>代码示例>>Python>>正文


Python TriggerInstance.query方法代码示例

本文整理汇总了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)
开发者ID:beryah,项目名称:st2,代码行数:22,代码来源:purge_trigger_instances.py

示例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
开发者ID:StackStorm,项目名称:st2,代码行数:67,代码来源:rule_enforcement_views.py


注:本文中的st2common.persistence.trigger.TriggerInstance.query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。