本文整理汇总了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
示例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
示例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])
示例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
示例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)
示例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)