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

Function update_execution

st2common/st2common/services/executions.py:192–234  ·  view source on GitHub ↗

:param set_result_size: True to calculate size of the serialized result field value and set it on the "result_size" database field.

(liveaction_db, publish=True, set_result_size=False)

Source from the content-addressed store, hash-verified

190
191
192def update_execution(liveaction_db, publish=True, set_result_size=False):
193 """
194 :param set_result_size: True to calculate size of the serialized result field value and set it
195 on the "result_size" database field.
196 """
197 execution = ActionExecution.get(liveaction__id=str(liveaction_db.id))
198
199 with coordination.get_coordinator().get_lock(str(liveaction_db.id).encode()):
200 # Skip execution object update when action is already in completed state.
201 if execution.status in action_constants.LIVEACTION_COMPLETED_STATES:
202 LOG.debug(
203 "[%s] Action is already in completed state: %s. Skipping execution update to state: %s."
204 % (execution.id, execution.status, liveaction_db.status)
205 )
206 return execution
207
208 decomposed = _decompose_liveaction(liveaction_db)
209
210 kw = {}
211 for k, v in six.iteritems(decomposed):
212 kw["set__" + k] = v
213
214 if liveaction_db.status != execution.status:
215 # Note: If the status changes we store this transition in the "log" attribute of action
216 # execution
217 kw["push__log"] = _create_execution_log_entry(liveaction_db.status)
218
219 if set_result_size:
220 # Sadly with the current ORM abstraction there is no better way to achieve updating
221 # result_size and we need to serialize the value again - luckily that operation is fast.
222 # To put things into perspective - on 4 MB result dictionary it only takes 7 ms which is
223 # negligible compared to other DB operations duration (and for smaller results it takes
224 # in sub ms range).
225 with Timer(key="action.executions.calculate_result_size"):
226 result_size = len(
227 ActionExecutionDB.result._serialize_field_value(
228 liveaction_db.result
229 )
230 )
231 kw["set__result_size"] = result_size
232
233 execution = ActionExecution.update(execution, publish=publish, **kw)
234 return execution
235
236
237def abandon_execution_if_incomplete(liveaction_id, publish=True):

Callers 1

Calls 7

TimerClass · 0.90
_decompose_liveactionFunction · 0.85
get_lockMethod · 0.80
getMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected