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

Function respond

st2common/st2common/services/inquiry.py:123–179  ·  view source on GitHub ↗
(inquiry, response, requester=None)

Source from the content-addressed store, hash-verified

121
122
123def respond(inquiry, response, requester=None):
124 # Set requester to system user is not provided.
125 if not requester:
126 requester = cfg.CONF.system_user.user
127
128 # Retrieve the liveaction from the database.
129 liveaction_db = lv_db_access.LiveAction.get_by_id(inquiry.liveaction.get("id"))
130
131 # Resume the parent workflow first. If the action execution for the inquiry is updated first,
132 # it triggers handling of the action execution completion which will interact with the paused
133 # parent workflow. The resuming logic that is executed here will then race with the completion
134 # of the inquiry action execution, which will randomly result in the parent workflow stuck in
135 # paused state.
136 if liveaction_db.context.get("parent"):
137 LOG.debug('Resuming workflow parent(s) for inquiry "%s".' % str(inquiry.id))
138
139 # For action execution under Action Chain workflows, request the entire
140 # workflow to resume. Orquesta handles resume differently and so does not require root
141 # to resume. Orquesta allows for specifc branches to resume while other is paused. When
142 # there is no other paused branches, the conductor will resume the rest of the workflow.
143 resume_target = (
144 action_service.get_parent_liveaction(liveaction_db)
145 if workflow_service.is_action_execution_under_workflow_context(
146 liveaction_db
147 )
148 else action_service.get_root_liveaction(liveaction_db)
149 )
150
151 if resume_target.status in action_constants.LIVEACTION_PAUSE_STATES:
152 action_service.request_resume(resume_target, requester)
153
154 # Succeed the liveaction and update result with the inquiry response.
155 LOG.debug('Updating response for inquiry "%s".' % str(inquiry.id))
156
157 result = fast_deepcopy_dict(inquiry.result)
158 result["response"] = response
159
160 liveaction_db = action_utils.update_liveaction_status(
161 status=action_constants.LIVEACTION_STATUS_SUCCEEDED,
162 end_timestamp=date_utils.get_datetime_utc_now(),
163 runner_info=sys_info_utils.get_process_info(),
164 result=result,
165 liveaction_id=str(liveaction_db.id),
166 )
167
168 # Sync the liveaction with the corresponding action execution.
169 execution_service.update_execution(liveaction_db)
170
171 # Invoke inquiry post run to trigger a callback to parent workflow.
172 LOG.debug('Invoking post run for inquiry "%s".' % str(inquiry.id))
173 runner_container = container.get_runner_container()
174 action_db = action_utils.get_action_by_ref(liveaction_db.action)
175 runnertype_db = action_utils.get_runnertype_by_name(action_db.runner_type["name"])
176 runner = runner_container._get_runner(runnertype_db, action_db, liveaction_db)
177 runner.post_run(status=action_constants.LIVEACTION_STATUS_SUCCEEDED, result=result)
178
179 return liveaction_db

Callers

nothing calls this directly

Calls 5

fast_deepcopy_dictFunction · 0.90
get_by_idMethod · 0.45
getMethod · 0.45
_get_runnerMethod · 0.45
post_runMethod · 0.45

Tested by

no test coverage detected