(self, liveaction_db)
| 48 | |
| 49 | class 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 |
no test coverage detected