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

Function create_execution_object

st2common/st2common/services/executions.py:105–167  ·  view source on GitHub ↗
(
    liveaction, action_db=None, runnertype_db=None, publish=True
)

Source from the content-addressed store, hash-verified

103
104
105def create_execution_object(
106 liveaction, action_db=None, runnertype_db=None, publish=True
107):
108 if not action_db:
109 action_db = action_utils.get_action_by_ref(liveaction.action)
110
111 if not runnertype_db:
112 runnertype_db = RunnerType.get_by_name(action_db.runner_type["name"])
113
114 attrs = {
115 "action": vars(ActionAPI.from_model(action_db)),
116 "parameters": liveaction["parameters"],
117 "runner": vars(RunnerTypeAPI.from_model(runnertype_db)),
118 }
119 attrs.update(_decompose_liveaction(liveaction))
120
121 if "rule" in liveaction.context:
122 rule = reference.get_model_from_ref(Rule, liveaction.context.get("rule", {}))
123 attrs["rule"] = vars(RuleAPI.from_model(rule))
124
125 if "trigger_instance" in liveaction.context:
126 trigger_instance_id = liveaction.context.get("trigger_instance", {})
127 trigger_instance_id = trigger_instance_id.get("id", None)
128 trigger_instance = TriggerInstance.get_by_id(trigger_instance_id)
129 trigger = reference.get_model_by_resource_ref(
130 db_api=Trigger, ref=trigger_instance.trigger
131 )
132 trigger_type = reference.get_model_by_resource_ref(
133 db_api=TriggerType, ref=trigger.type
134 )
135 trigger_instance = reference.get_model_from_ref(
136 TriggerInstance, liveaction.context.get("trigger_instance", {})
137 )
138 attrs["trigger_instance"] = vars(
139 TriggerInstanceAPI.from_model(trigger_instance)
140 )
141 attrs["trigger"] = vars(TriggerAPI.from_model(trigger))
142 attrs["trigger_type"] = vars(TriggerTypeAPI.from_model(trigger_type))
143
144 parent = _get_parent_execution(liveaction)
145 if parent:
146 attrs["parent"] = str(parent.id)
147
148 attrs["log"] = [_create_execution_log_entry(liveaction["status"])]
149
150 # TODO: This object initialization takes 20-30or so ms
151 execution = ActionExecutionDB(**attrs)
152 # TODO: Do 100% research this is fully safe and unique in distributed setups
153 execution.id = ObjectId()
154 execution.web_url = _get_web_url_for_execution(str(execution.id))
155
156 # NOTE: User input data is already validate as part of the API request,
157 # other data is set by us. Skipping validation here makes operation 10%-30% faster
158 execution = ActionExecution.add_or_update(
159 execution, publish=publish, validate=False
160 )
161
162 if parent and str(execution.id) not in parent.children:

Callers

nothing calls this directly

Calls 11

ActionExecutionDBClass · 0.90
_decompose_liveactionFunction · 0.85
_get_parent_executionFunction · 0.85
get_by_nameMethod · 0.45
from_modelMethod · 0.45
updateMethod · 0.45
getMethod · 0.45
get_by_idMethod · 0.45
add_or_updateMethod · 0.45

Tested by

no test coverage detected