當前位置: 首頁>>代碼示例>>Python>>正文


Python Trace.push_components方法代碼示例

本文整理匯總了Python中st2common.persistence.trace.Trace.push_components方法的典型用法代碼示例。如果您正苦於以下問題:Python Trace.push_components方法的具體用法?Python Trace.push_components怎麽用?Python Trace.push_components使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在st2common.persistence.trace.Trace的用法示例。


在下文中一共展示了Trace.push_components方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: add_or_update_given_trace_db

# 需要導入模塊: from st2common.persistence.trace import Trace [as 別名]
# 或者: from st2common.persistence.trace.Trace import push_components [as 別名]
def add_or_update_given_trace_db(trace_db, action_executions=None, rules=None,
                                 trigger_instances=None):
    """
    Will update an existing Trace.

    :param trace_db: The TraceDB to update.
    :type trace_db: ``TraceDB``

    :param action_executions: The action_execution to be added to the Trace. Should a list
                              of object_ids or a dict containing object_ids and caused_by.
    :type action_executions: ``list``

    :param rules: The rules to be added to the Trace. Should a list of object_ids or a dict
                  containing object_ids and caused_by.
    :type rules: ``list``

    :param trigger_instances: The trigger_instances to be added to the Trace. Should a list
                              of object_ids or a dict containing object_ids and caused_by.
    :type trigger_instances: ``list``

    :rtype: ``TraceDB``
    """
    if trace_db is None:
        raise ValueError('trace_db should be non-None.')

    if not action_executions:
        action_executions = []
    action_executions = [_to_trace_component_db(component=action_execution)
                         for action_execution in action_executions]

    if not rules:
        rules = []
    rules = [_to_trace_component_db(component=rule) for rule in rules]

    if not trigger_instances:
        trigger_instances = []
    trigger_instances = [_to_trace_component_db(component=trigger_instance)
                         for trigger_instance in trigger_instances]

    # If an id exists then this is an update and we do not want to perform
    # an upsert so use push_components which will use the push operator.
    if trace_db.id:
        return Trace.push_components(trace_db,
                                     action_executions=action_executions,
                                     rules=rules,
                                     trigger_instances=trigger_instances)

    trace_db.action_executions = action_executions
    trace_db.rules = rules
    trace_db.trigger_instances = trigger_instances

    return Trace.add_or_update(trace_db)
開發者ID:azamsheriff,項目名稱:st2,代碼行數:54,代碼來源:trace.py

示例2: test_update_via_list_push_components

# 需要導入模塊: from st2common.persistence.trace import Trace [as 別名]
# 或者: from st2common.persistence.trace.Trace import push_components [as 別名]
    def test_update_via_list_push_components(self):
        no_action_executions = 4
        no_rules = 4
        no_trigger_instances = 5
        saved = TraceDBTest._create_save_trace(
            trace_tag='test_trace',
            action_executions=[str(bson.ObjectId()) for _ in range(no_action_executions)],
            rules=[str(bson.ObjectId()) for _ in range(no_rules)],
            trigger_instances=[str(bson.ObjectId()) for _ in range(no_trigger_instances)])

        retrieved = Trace.push_components(
            saved,
            action_executions=[TraceComponentDB(object_id=str(bson.ObjectId()))
                               for _ in range(no_action_executions)],
            rules=[TraceComponentDB(object_id=str(bson.ObjectId()))
                   for _ in range(no_rules)],
            trigger_instances=[TraceComponentDB(object_id=str(bson.ObjectId()))
                               for _ in range(no_trigger_instances)])

        self.assertEquals(retrieved.id, saved.id, 'Incorrect trace retrieved.')
        self.assertEquals(len(retrieved.action_executions), no_action_executions * 2)
        self.assertEquals(len(retrieved.rules), no_rules * 2)
        self.assertEquals(len(retrieved.trigger_instances), no_trigger_instances * 2)
開發者ID:AlexeyDeyneko,項目名稱:st2,代碼行數:25,代碼來源:test_db_trace.py


注:本文中的st2common.persistence.trace.Trace.push_components方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。