(liveaction_db, action_db=None)
| 189 | |
| 190 | |
| 191 | def invoke_post_run(liveaction_db, action_db=None): |
| 192 | # NOTE: This import has intentionally been moved here to avoid massive performance overhead |
| 193 | # (1+ second) for other functions inside this module which don't need to use those imports. |
| 194 | from st2common.runners import base as runners |
| 195 | from st2common.util import action_db as action_db_utils |
| 196 | from st2common.content import utils as content_utils |
| 197 | |
| 198 | LOG.info("Invoking post run for action execution %s.", liveaction_db.id) |
| 199 | |
| 200 | # Identify action and runner. |
| 201 | if not action_db: |
| 202 | action_db = action_db_utils.get_action_by_ref(liveaction_db.action) |
| 203 | |
| 204 | if not action_db: |
| 205 | LOG.error( |
| 206 | "Unable to invoke post run. Action %s no longer exists.", |
| 207 | liveaction_db.action, |
| 208 | ) |
| 209 | return |
| 210 | |
| 211 | LOG.info( |
| 212 | "Action execution %s runs %s of runner type %s.", |
| 213 | liveaction_db.id, |
| 214 | action_db.name, |
| 215 | action_db.runner_type["name"], |
| 216 | ) |
| 217 | |
| 218 | # Get instance of the action runner and related configuration. |
| 219 | runner_type_db = action_db_utils.get_runnertype_by_name( |
| 220 | action_db.runner_type["name"] |
| 221 | ) |
| 222 | |
| 223 | runner = runners.get_runner(name=runner_type_db.name) |
| 224 | |
| 225 | entry_point = content_utils.get_entry_point_abs_path( |
| 226 | pack=action_db.pack, entry_point=action_db.entry_point |
| 227 | ) |
| 228 | |
| 229 | libs_dir_path = content_utils.get_action_libs_abs_path( |
| 230 | pack=action_db.pack, entry_point=action_db.entry_point |
| 231 | ) |
| 232 | |
| 233 | # Configure the action runner. |
| 234 | runner.runner_type_db = runner_type_db |
| 235 | runner.action = action_db |
| 236 | runner.action_name = action_db.name |
| 237 | runner.liveaction = liveaction_db |
| 238 | runner.liveaction_id = str(liveaction_db.id) |
| 239 | runner.entry_point = entry_point |
| 240 | runner.context = getattr(liveaction_db, "context", dict()) |
| 241 | runner.callback = getattr(liveaction_db, "callback", dict()) |
| 242 | runner.libs_dir_path = libs_dir_path |
| 243 | |
| 244 | # Invoke the post_run method. |
| 245 | runner.post_run(liveaction_db.status, liveaction_db.result) |
no test coverage detected