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


Python TriggerInstance.add_or_update方法代码示例

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


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

示例1: test_no_timestamp_doesnt_delete

# 需要导入模块: from st2common.persistence.trigger import TriggerInstance [as 别名]
# 或者: from st2common.persistence.trigger.TriggerInstance import add_or_update [as 别名]
    def test_no_timestamp_doesnt_delete(self):
        now = date_utils.get_datetime_utc_now()

        instance_db = TriggerInstanceDB(trigger='purge_tool.dummy.trigger',
                                        payload={'hola': 'hi', 'kuraci': 'chicken'},
                                        occurrence_time=now - timedelta(days=20))
        TriggerInstance.add_or_update(instance_db)

        self.assertEqual(len(TriggerInstance.get_all()), 1)
        purge_trigger_instances()
        self.assertEqual(len(TriggerInstance.get_all()), 1)
开发者ID:beryah,项目名称:st2,代码行数:13,代码来源:test_purge_trigger_instances.py

示例2: test_no_timestamp_doesnt_delete

# 需要导入模块: from st2common.persistence.trigger import TriggerInstance [as 别名]
# 或者: from st2common.persistence.trigger.TriggerInstance import add_or_update [as 别名]
    def test_no_timestamp_doesnt_delete(self):
        now = date_utils.get_datetime_utc_now()

        instance_db = TriggerInstanceDB(trigger='purge_tool.dummy.trigger',
                                        payload={'hola': 'hi', 'kuraci': 'chicken'},
                                        occurrence_time=now - timedelta(days=20))
        TriggerInstance.add_or_update(instance_db)

        self.assertEqual(len(TriggerInstance.get_all()), 1)
        expected_msg = 'Specify a valid timestamp'
        self.assertRaisesRegexp(ValueError, expected_msg,
                                purge_trigger_instances,
                                logger=LOG, timestamp=None)
        self.assertEqual(len(TriggerInstance.get_all()), 1)
开发者ID:AlexeyDeyneko,项目名称:st2,代码行数:16,代码来源:test_purge_trigger_instances.py

示例3: create_trigger_instance

# 需要导入模块: from st2common.persistence.trigger import TriggerInstance [as 别名]
# 或者: from st2common.persistence.trigger.TriggerInstance import add_or_update [as 别名]
def create_trigger_instance(trigger, payload, occurrence_time, raise_on_no_trigger=False):
    """
    This creates a trigger instance object given trigger and payload.
    Trigger can be just a string reference (pack.name) or a ``dict`` containing 'id' or
    'uid' or type' and 'parameters' keys.

    :param trigger: Trigger reference or dictionary with trigger query filters.
    :type trigger: ``str`` or ``dict``

    :param payload: Trigger payload.
    :type payload: ``dict``
    """
    trigger_db = get_trigger_db_by_ref_or_dict(trigger=trigger)

    if not trigger_db:
        LOG.debug('No trigger in db for %s', trigger)
        if raise_on_no_trigger:
            raise StackStormDBObjectNotFoundError('Trigger not found for %s' % trigger)
        return None

    trigger_ref = trigger_db.get_reference().ref

    trigger_instance = TriggerInstanceDB()
    trigger_instance.trigger = trigger_ref
    trigger_instance.payload = payload
    trigger_instance.occurrence_time = occurrence_time
    trigger_instance.status = TRIGGER_INSTANCE_PENDING
    return TriggerInstance.add_or_update(trigger_instance)
开发者ID:nzlosh,项目名称:st2,代码行数:30,代码来源:utils.py

示例4: create_trigger_instance

# 需要导入模块: from st2common.persistence.trigger import TriggerInstance [as 别名]
# 或者: from st2common.persistence.trigger.TriggerInstance import add_or_update [as 别名]
def create_trigger_instance(trigger, payload, occurrence_time, raise_on_no_trigger=False):
    """
    This creates a trigger instance object given trigger and payload.
    Trigger can be just a string reference (pack.name) or a ``dict``
    containing  'type' and 'parameters'.

    :param trigger: Dictionary with trigger query filters.
    :type trigger: ``dict``

    :param payload: Trigger payload.
    :type payload: ``dict``
    """
    # TODO: This is nasty, this should take a unique reference and not a dict
    if isinstance(trigger, six.string_types):
        trigger_db = TriggerService.get_trigger_db_by_ref(trigger)
    else:
        type_ = trigger.get('type', None)
        parameters = trigger.get('parameters', {})
        trigger_db = TriggerService.get_trigger_db_given_type_and_params(type=type_,
                                                                         parameters=parameters)

    if trigger_db is None:
        LOG.debug('No trigger in db for %s', trigger)
        if raise_on_no_trigger:
            raise StackStormDBObjectNotFoundError('Trigger not found for %s', trigger)
        return None

    trigger_ref = trigger_db.get_reference().ref

    trigger_instance = TriggerInstanceDB()
    trigger_instance.trigger = trigger_ref
    trigger_instance.payload = payload
    trigger_instance.occurrence_time = occurrence_time
    trigger_instance.status = TRIGGER_INSTANCE_PENDING
    return TriggerInstance.add_or_update(trigger_instance)
开发者ID:E-LLP,项目名称:st2,代码行数:37,代码来源:utils.py

示例5: _create_trigger_instance

# 需要导入模块: from st2common.persistence.trigger import TriggerInstance [as 别名]
# 或者: from st2common.persistence.trigger.TriggerInstance import add_or_update [as 别名]
 def _create_trigger_instance(cls, trigger_ref, payload):
     trigger_instance = TriggerInstanceDB()
     trigger_instance.trigger = trigger_ref
     trigger_instance.payload = payload
     trigger_instance.occurrence_time = datetime.datetime.utcnow()
     created = TriggerInstance.add_or_update(trigger_instance)
     cls.triggerinstance_count += 1
     return created
开发者ID:jtopjian,项目名称:st2,代码行数:10,代码来源:test_triggerinstances.py

示例6: _create_save_triggerinstance

# 需要导入模块: from st2common.persistence.trigger import TriggerInstance [as 别名]
# 或者: from st2common.persistence.trigger.TriggerInstance import add_or_update [as 别名]
 def _create_save_triggerinstance(trigger):
     created = TriggerInstanceDB(
         trigger=trigger.get_reference().ref,
         payload={},
         occurrence_time=date_utils.get_datetime_utc_now(),
         status=TRIGGER_INSTANCE_PROCESSED,
     )
     return TriggerInstance.add_or_update(created)
开发者ID:rlugojr,项目名称:st2,代码行数:10,代码来源:test_db.py

示例7: test_purge

# 需要导入模块: from st2common.persistence.trigger import TriggerInstance [as 别名]
# 或者: from st2common.persistence.trigger.TriggerInstance import add_or_update [as 别名]
    def test_purge(self):
        now = date_utils.get_datetime_utc_now()

        instance_db = TriggerInstanceDB(trigger='purge_tool.dummy.trigger',
                                        payload={'hola': 'hi', 'kuraci': 'chicken'},
                                        occurrence_time=now - timedelta(days=20),
                                        status=TRIGGER_INSTANCE_PROCESSED)
        TriggerInstance.add_or_update(instance_db)

        instance_db = TriggerInstanceDB(trigger='purge_tool.dummy.trigger',
                                        payload={'hola': 'hi', 'kuraci': 'chicken'},
                                        occurrence_time=now - timedelta(days=5),
                                        status=TRIGGER_INSTANCE_PROCESSED)
        TriggerInstance.add_or_update(instance_db)

        self.assertEqual(len(TriggerInstance.get_all()), 2)
        purge_trigger_instances(logger=LOG, timestamp=now - timedelta(days=10))
        self.assertEqual(len(TriggerInstance.get_all()), 1)
开发者ID:Bala96,项目名称:st2,代码行数:20,代码来源:test_purge_trigger_instances.py

示例8: create_trigger_instance

# 需要导入模块: from st2common.persistence.trigger import TriggerInstance [as 别名]
# 或者: from st2common.persistence.trigger.TriggerInstance import add_or_update [as 别名]
def create_trigger_instance(trigger, payload, occurrence_time, raise_on_no_trigger=False):
    """
    This creates a trigger instance object given trigger and payload.
    Trigger can be just a string reference (pack.name) or a ``dict`` containing 'id' or
    'uid' or type' and 'parameters' keys.

    :param trigger: Trigger reference or dictionary with trigger query filters.
    :type trigger: ``str`` or ``dict``

    :param payload: Trigger payload.
    :type payload: ``dict``
    """
    # TODO: This is nasty, this should take a unique reference and not a dict
    if isinstance(trigger, six.string_types):
        trigger_db = TriggerService.get_trigger_db_by_ref(trigger)
    else:
        # If id / uid is available we try to look up Trigger by id. This way we can avoid bug in
        # pymongo / mongoengine related to "parameters" dictionary lookups
        trigger_id = trigger.get('id', None)
        trigger_uid = trigger.get('uid', None)

        # TODO: Remove parameters dictionary look up when we can confirm each trigger dictionary
        # passed to this method always contains id or uid
        if trigger_id:
            LOG.debug('Looking up TriggerDB by id: %s', trigger_id)
            trigger_db = TriggerService.get_trigger_db_by_id(id=trigger_id)
        elif trigger_uid:
            LOG.debug('Looking up TriggerDB by uid: %s', trigger_uid)
            trigger_db = TriggerService.get_trigger_db_by_uid(uid=trigger_uid)
        else:
            # Last resort - look it up by parameters
            trigger_type = trigger.get('type', None)
            parameters = trigger.get('parameters', {})

            LOG.debug('Looking up TriggerDB by type and parameters: type=%s, parameters=%s',
                      trigger_type, parameters)
            trigger_db = TriggerService.get_trigger_db_given_type_and_params(type=trigger_type,
                                                                             parameters=parameters)

    if trigger_db is None:
        LOG.debug('No trigger in db for %s', trigger)
        if raise_on_no_trigger:
            raise StackStormDBObjectNotFoundError('Trigger not found for %s', trigger)
        return None

    trigger_ref = trigger_db.get_reference().ref

    trigger_instance = TriggerInstanceDB()
    trigger_instance.trigger = trigger_ref
    trigger_instance.payload = payload
    trigger_instance.occurrence_time = occurrence_time
    trigger_instance.status = TRIGGER_INSTANCE_PENDING
    return TriggerInstance.add_or_update(trigger_instance)
开发者ID:Gagaro,项目名称:st2,代码行数:55,代码来源:utils.py

示例9: _create_trigger_instance

# 需要导入模块: from st2common.persistence.trigger import TriggerInstance [as 别名]
# 或者: from st2common.persistence.trigger.TriggerInstance import add_or_update [as 别名]
    def _create_trigger_instance(cls, trigger_ref, payload, seconds):
        # Note: We use 1 second intervals between occurence time to prevent
        # occasional test failures
        occurrence_time = date_utils.get_datetime_utc_now()
        occurrence_time = occurrence_time + datetime.timedelta(seconds=seconds)

        trigger_instance = TriggerInstanceDB()
        trigger_instance.trigger = trigger_ref
        trigger_instance.payload = payload
        trigger_instance.occurrence_time = occurrence_time
        created = TriggerInstance.add_or_update(trigger_instance)
        cls.triggerinstance_count += 1
        return created
开发者ID:AlexeyDeyneko,项目名称:st2,代码行数:15,代码来源:test_triggerinstances.py

示例10: test_triggered_execution

# 需要导入模块: from st2common.persistence.trigger import TriggerInstance [as 别名]
# 或者: from st2common.persistence.trigger.TriggerInstance import add_or_update [as 别名]
    def test_triggered_execution(self):
        docs = {
            'trigger_type': copy.deepcopy(fixture.ARTIFACTS['trigger_type']),
            'trigger': copy.deepcopy(fixture.ARTIFACTS['trigger']),
            'rule': copy.deepcopy(fixture.ARTIFACTS['rule']),
            'trigger_instance': copy.deepcopy(fixture.ARTIFACTS['trigger_instance'])}

        # Trigger an action execution.
        trigger_type = TriggerType.add_or_update(
            TriggerTypeAPI.to_model(TriggerTypeAPI(**docs['trigger_type'])))
        trigger = Trigger.add_or_update(TriggerAPI.to_model(TriggerAPI(**docs['trigger'])))
        rule = RuleAPI.to_model(RuleAPI(**docs['rule']))
        rule.trigger = reference.get_str_resource_ref_from_model(trigger)
        rule = Rule.add_or_update(rule)
        trigger_instance = TriggerInstance.add_or_update(
            TriggerInstanceAPI.to_model(TriggerInstanceAPI(**docs['trigger_instance'])))
        trace_service.add_or_update_given_trace_context(
            trace_context={'trace_tag': 'test_triggered_execution_trace'},
            trigger_instances=[str(trigger_instance.id)])
        enforcer = RuleEnforcer(trigger_instance, rule)
        enforcer.enforce()

        # Wait for the action execution to complete and then confirm outcome.
        liveaction = LiveAction.get(context__trigger_instance__id=str(trigger_instance.id))
        self.assertIsNotNone(liveaction)
        liveaction = self._wait_on_status(liveaction, action_constants.LIVEACTION_STATUS_FAILED)

        execution = self._get_action_execution(
            liveaction__id=str(liveaction.id),
            raise_exception=True
        )

        self.assertDictEqual(execution.trigger, vars(TriggerAPI.from_model(trigger)))
        self.assertDictEqual(execution.trigger_type, vars(TriggerTypeAPI.from_model(trigger_type)))
        self.assertDictEqual(execution.trigger_instance,
                             vars(TriggerInstanceAPI.from_model(trigger_instance)))
        self.assertDictEqual(execution.rule, vars(RuleAPI.from_model(rule)))
        action = action_utils.get_action_by_ref(liveaction.action)
        self.assertDictEqual(execution.action, vars(ActionAPI.from_model(action)))
        runner = RunnerType.get_by_name(action.runner_type['name'])
        self.assertDictEqual(execution.runner, vars(RunnerTypeAPI.from_model(runner)))
        liveaction = LiveAction.get_by_id(str(liveaction.id))
        self.assertEqual(execution.start_timestamp, liveaction.start_timestamp)
        self.assertEqual(execution.end_timestamp, liveaction.end_timestamp)
        self.assertEqual(execution.result, liveaction.result)
        self.assertEqual(execution.status, liveaction.status)
        self.assertEqual(execution.context, liveaction.context)
        self.assertEqual(execution.liveaction['callback'], liveaction.callback)
        self.assertEqual(execution.liveaction['action'], liveaction.action)
开发者ID:StackStorm,项目名称:st2,代码行数:51,代码来源:test_executions.py

示例11: _create_save_triggerinstance

# 需要导入模块: from st2common.persistence.trigger import TriggerInstance [as 别名]
# 或者: from st2common.persistence.trigger.TriggerInstance import add_or_update [as 别名]
 def _create_save_triggerinstance(trigger):
     created = TriggerInstanceDB(trigger=trigger.get_reference().ref, payload={},
                                 occurrence_time=date_utils.get_datetime_utc_now())
     return TriggerInstance.add_or_update(created)
开发者ID:azamsheriff,项目名称:st2,代码行数:6,代码来源:test_db.py

示例12: update_trigger_instance_status

# 需要导入模块: from st2common.persistence.trigger import TriggerInstance [as 别名]
# 或者: from st2common.persistence.trigger.TriggerInstance import add_or_update [as 别名]
def update_trigger_instance_status(trigger_instance, status):
    trigger_instance.status = status
    return TriggerInstance.add_or_update(trigger_instance)
开发者ID:nzlosh,项目名称:st2,代码行数:5,代码来源:utils.py


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