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

Method _update_status

st2actions/st2actions/container/base.py:343–421  ·  view source on GitHub ↗
(self, liveaction_id, status, result, context)

Source from the content-addressed store, hash-verified

341 return (liveaction_db, state_changed)
342
343 def _update_status(self, liveaction_id, status, result, context):
344 with Timer(key="action.executions.update_liveaction_db"):
345 try:
346 # NOTE: The next two operations take a very long time in master with large executions
347 # (long standing issue), but because start_timestamp and end_timestamp measure how long
348 # it took for the runner to run the action, it doesn't include the time it took to
349 # actually write results / persist execution into the database - that's a problem
350 # because we have no good direct visibility into that.
351 #
352 # The UX user would experience is - they would run an action which produces large
353 # result, CLI / API would show execution as running for a long time (until it's
354 # persisted in the database), but when it will finally be written to the database,
355 # duration will be shown as a short time, because it's measured based on start and
356 # end timestamp.
357 #
358 # This mean we can have, for example, Python runner action which returns a lot of data
359 # and takes only 0.5 second to finish, but next two database operations can easily take
360 # 10 seconds each.
361 #
362 # To work around that and provide some additional visibility into that to the operators
363 # and users, we update "end_timestamp" on each object again after both of them have
364 # already been written. That atomic single field update is very fast and adds no
365 # additional overhead.
366 LOG.debug(
367 "Setting status: %s for liveaction: %s", status, liveaction_id
368 )
369 liveaction_db, state_changed = self._update_live_action_db(
370 liveaction_id, status, result, context
371 )
372 except Exception as e:
373 LOG.exception(
374 "Cannot update liveaction "
375 "(id: %s, status: %s, result: %s)."
376 % (liveaction_id, status, result)
377 )
378 raise e
379
380 # live_action_written_to_db_dt = date_utils.get_datetime_utc_now()
381
382 with Timer(key="action.executions.update_execution_db"):
383 try:
384 executions.update_execution(
385 liveaction_db,
386 publish=state_changed,
387 set_result_size=True,
388 )
389 extra = {"liveaction_db": liveaction_db}
390 LOG.debug("Updated liveaction after run", extra=extra)
391 except Exception as e:
392 LOG.exception(
393 "Cannot update action execution for liveaction "
394 "(id: %s, status: %s, result: %s)."
395 % (liveaction_id, status, result)
396 )
397 raise e
398
399 # execution_written_to_db = date_utils.get_datetime_utc_now()
400

Callers 4

_do_runMethod · 0.95
_do_cancelMethod · 0.95
_do_pauseMethod · 0.95
_do_resumeMethod · 0.95

Calls 2

TimerClass · 0.90

Tested by

no test coverage detected