MCPcopy Create free account
hub / github.com/StackStorm/st2 / add_or_update_given_trace_db

Function add_or_update_given_trace_db

st2common/st2common/services/trace.py:253–311  ·  view source on GitHub ↗

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.

(
    trace_db, action_executions=None, rules=None, trigger_instances=None
)

Source from the content-addressed store, hash-verified

251
252
253def add_or_update_given_trace_db(
254 trace_db, action_executions=None, rules=None, trigger_instances=None
255):
256 """
257 Will update an existing Trace.
258
259 :param trace_db: The TraceDB to update.
260 :type trace_db: ``TraceDB``
261
262 :param action_executions: The action_execution to be added to the Trace. Should a list
263 of object_ids or a dict containing object_ids and caused_by.
264 :type action_executions: ``list``
265
266 :param rules: The rules to be added to the Trace. Should a list of object_ids or a dict
267 containing object_ids and caused_by.
268 :type rules: ``list``
269
270 :param trigger_instances: The trigger_instances to be added to the Trace. Should a list
271 of object_ids or a dict containing object_ids and caused_by.
272 :type trigger_instances: ``list``
273
274 :rtype: ``TraceDB``
275 """
276 if trace_db is None:
277 raise ValueError("trace_db should be non-None.")
278
279 if not action_executions:
280 action_executions = []
281 action_executions = [
282 _to_trace_component_db(component=action_execution)
283 for action_execution in action_executions
284 ]
285
286 if not rules:
287 rules = []
288 rules = [_to_trace_component_db(component=rule) for rule in rules]
289
290 if not trigger_instances:
291 trigger_instances = []
292 trigger_instances = [
293 _to_trace_component_db(component=trigger_instance)
294 for trigger_instance in trigger_instances
295 ]
296
297 # If an id exists then this is an update and we do not want to perform
298 # an upsert so use push_components which will use the push operator.
299 if trace_db.id:
300 return Trace.push_components(
301 trace_db,
302 action_executions=action_executions,
303 rules=rules,
304 trigger_instances=trigger_instances,
305 )
306
307 trace_db.action_executions = action_executions
308 trace_db.rules = rules
309 trace_db.trigger_instances = trigger_instances
310

Callers 1

Calls 3

_to_trace_component_dbFunction · 0.85
push_componentsMethod · 0.80
add_or_updateMethod · 0.45

Tested by

no test coverage detected