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


Python Trigger.query方法代码示例

本文整理汇总了Python中st2common.persistence.trigger.Trigger.query方法的典型用法代码示例。如果您正苦于以下问题:Python Trigger.query方法的具体用法?Python Trigger.query怎么用?Python Trigger.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在st2common.persistence.trigger.Trigger的用法示例。


在下文中一共展示了Trigger.query方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_trigger_db_given_type_and_params

# 需要导入模块: from st2common.persistence.trigger import Trigger [as 别名]
# 或者: from st2common.persistence.trigger.Trigger import query [as 别名]
def get_trigger_db_given_type_and_params(type=None, parameters=None):
    try:
        parameters = parameters or {}
        trigger_dbs = Trigger.query(type=type, parameters=parameters)

        trigger_db = trigger_dbs[0] if len(trigger_dbs) > 0 else None

        # NOTE: This is a work-around which we might be able to remove once we upgrade
        # pymongo and mongoengine
        # Work around for cron-timer when in some scenarios finding an object fails when Python
        # value types are unicode :/
        is_cron_trigger = type == CRON_TIMER_TRIGGER_REF
        has_parameters = bool(parameters)

        if not trigger_db and six.PY2 and is_cron_trigger and has_parameters:
            non_unicode_literal_parameters = {}
            for key, value in six.iteritems(parameters):
                key = key.encode("utf-8")

                if isinstance(value, six.text_type):
                    # We only encode unicode to str
                    value = value.encode("utf-8")

                non_unicode_literal_parameters[key] = value
            parameters = non_unicode_literal_parameters

            trigger_dbs = Trigger.query(type=type, parameters=non_unicode_literal_parameters).no_cache()

            # Note: We need to directly access the object, using len or accessing the query set
            # twice won't work - there seems to bug a bug with cursor where accessing it twice
            # will throw an exception
            try:
                trigger_db = trigger_dbs[0]
            except IndexError:
                trigger_db = None

        if not parameters and not trigger_db:
            # We need to do double query because some TriggeDB objects without
            # parameters have "parameters" attribute stored in the db and others
            # don't
            trigger_db = Trigger.query(type=type, parameters=None).first()

        return trigger_db
    except StackStormDBObjectNotFoundError as e:
        LOG.debug(
            'Database lookup for type="%s" parameters="%s" resulted ' + "in exception : %s.",
            type,
            parameters,
            e,
            exc_info=True,
        )
        return None
开发者ID:rlugojr,项目名称:st2,代码行数:54,代码来源:triggers.py

示例2: get_all

# 需要导入模块: from st2common.persistence.trigger import Trigger [as 别名]
# 或者: from st2common.persistence.trigger.Trigger import query [as 别名]
    def get_all(self, exclude_attributes=None, include_attributes=None, sort=None, offset=0,
                limit=None, requester_user=None, **raw_filters):
        """
            List all triggerinstances.

            Handles requests:
                GET /triggerinstances/
        """
        # If trigger_type filter is provided, filter based on the TriggerType via Trigger object
        trigger_type_ref = raw_filters.get('trigger_type', None)

        if trigger_type_ref:
            # 1. Retrieve TriggerType object id which match this trigger_type ref
            trigger_dbs = Trigger.query(type=trigger_type_ref,
                                        only_fields=['ref', 'name', 'pack', 'type'])
            trigger_refs = [trigger_db.ref for trigger_db in trigger_dbs]
            raw_filters['trigger'] = trigger_refs

        if trigger_type_ref and len(raw_filters.get('trigger', [])) == 0:
            # Empty list means trigger_type_ref filter was provided, but we matched no Triggers so
            # we should return back empty result
            return []

        trigger_instances = self._get_trigger_instances(exclude_fields=exclude_attributes,
                                                        include_fields=include_attributes,
                                                        sort=sort,
                                                        offset=offset,
                                                        limit=limit,
                                                        raw_filters=raw_filters,
                                                        requester_user=requester_user)
        return trigger_instances
开发者ID:StackStorm,项目名称:st2,代码行数:33,代码来源:triggers.py

示例3: test_trigger_lookup

# 需要导入模块: from st2common.persistence.trigger import Trigger [as 别名]
# 或者: from st2common.persistence.trigger.Trigger import query [as 别名]
 def test_trigger_lookup(self):
     triggertype = ReactorModelTest._create_save_triggertype()
     saved = ReactorModelTest._create_save_trigger(triggertype)
     retrievedtriggers = Trigger.query(name=saved.name)
     self.assertEqual(1, len(retrievedtriggers), "No triggers found.")
     for retrievedtrigger in retrievedtriggers:
         self.assertEqual(saved.id, retrievedtrigger.id, "Incorrect trigger returned.")
     ReactorModelTest._delete([saved, triggertype])
开发者ID:rlugojr,项目名称:st2,代码行数:10,代码来源:test_db.py

示例4: get_trigger_db_given_type_and_params

# 需要导入模块: from st2common.persistence.trigger import Trigger [as 别名]
# 或者: from st2common.persistence.trigger.Trigger import query [as 别名]
def get_trigger_db_given_type_and_params(type=None, parameters=None):
    try:
        parameters = parameters or {}

        trigger_db = Trigger.query(type=type,
                                   parameters=parameters).first()

        if not parameters and not trigger_db:
            # We need to do double query because some TriggeDB objects without
            # parameters have "parameters" attribute stored in the db and others
            # don't
            trigger_db = Trigger.query(type=type, parameters=None).first()

        return trigger_db
    except ValueError as e:
        LOG.debug('Database lookup for type="%s" parameters="%s" resulted ' +
                  'in exception : %s.', type, parameters, e, exc_info=True)
        return None
开发者ID:ruslantum,项目名称:st2,代码行数:20,代码来源:triggers.py

示例5: _load_triggers_from_db

# 需要导入模块: from st2common.persistence.trigger import Trigger [as 别名]
# 或者: from st2common.persistence.trigger.Trigger import query [as 别名]
 def _load_triggers_from_db(self):
     for trigger_type in self._trigger_types:
         for trigger in Trigger.query(type=trigger_type):
             LOG.debug('Found existing trigger: %s in db.' % trigger)
             self._handlers[publishers.CREATE_RK](trigger)
开发者ID:Bala96,项目名称:st2,代码行数:7,代码来源:triggerwatcher.py

示例6: _validate_shadow_trigger

# 需要导入模块: from st2common.persistence.trigger import Trigger [as 别名]
# 或者: from st2common.persistence.trigger.Trigger import query [as 别名]
 def _validate_shadow_trigger(self, trigger_type_db):
     if trigger_type_db.parameters_schema:
         return
     trigger_type_ref = trigger_type_db.get_reference().ref
     triggers = Trigger.query(type=trigger_type_ref)
     self.assertTrue(len(triggers) > 0, 'Shadow trigger not created for %s.' % trigger_type_ref)
开发者ID:StackStorm,项目名称:st2,代码行数:8,代码来源:test_register_internal_trigger.py


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