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

Method dispatch

st2actions/st2actions/container/base.py:50–90  ·  view source on GitHub ↗
(self, liveaction_db)

Source from the content-addressed store, hash-verified

48
49class RunnerContainer(object):
50 def dispatch(self, liveaction_db):
51 action_db = get_action_by_ref(liveaction_db.action)
52 if not action_db:
53 raise Exception("Action %s not found in DB." % (liveaction_db.action))
54
55 liveaction_db.context["pack"] = action_db.pack
56
57 runner_type_db = get_runnertype_by_name(action_db.runner_type["name"])
58
59 extra = {"liveaction_db": liveaction_db, "runner_type_db": runner_type_db}
60 LOG.info("Dispatching Action to a runner", extra=extra)
61
62 # Get runner instance.
63 runner = self._get_runner(runner_type_db, action_db, liveaction_db)
64
65 LOG.debug(
66 'Runner instance for RunnerType "%s" is: %s', runner_type_db.name, runner
67 )
68
69 # Process the request.
70 funcs = {
71 action_constants.LIVEACTION_STATUS_REQUESTED: self._do_run,
72 action_constants.LIVEACTION_STATUS_SCHEDULED: self._do_run,
73 action_constants.LIVEACTION_STATUS_RUNNING: self._do_run,
74 action_constants.LIVEACTION_STATUS_CANCELING: self._do_cancel,
75 action_constants.LIVEACTION_STATUS_PAUSING: self._do_pause,
76 action_constants.LIVEACTION_STATUS_RESUMING: self._do_resume,
77 }
78
79 if liveaction_db.status not in funcs:
80 raise actionrunner.ActionRunnerDispatchError(
81 "Action runner is unable to dispatch the liveaction because it is "
82 'in an unsupported status of "%s".' % liveaction_db.status
83 )
84
85 with CounterWithTimer(key="action.executions"):
86 status = liveaction_db.status
87 with CounterWithTimer(key="action.executions.process.%s" % (status)):
88 liveaction_db = funcs[liveaction_db.status](runner)
89
90 return liveaction_db.result
91
92 def _do_run(self, runner):
93 # Create a temporary auth token which will be available

Callers 8

_run_actionMethod · 0.45
_cancel_actionMethod · 0.45
_pause_actionMethod · 0.45
_resume_actionMethod · 0.45
_post_generic_triggerMethod · 0.45
postMethod · 0.45

Calls 4

_get_runnerMethod · 0.95
get_action_by_refFunction · 0.90
get_runnertype_by_nameFunction · 0.90
CounterWithTimerClass · 0.90

Tested by

no test coverage detected