def create_action_execution(action_def, action_input, task_ex=None, index=0, description=''): # TODO(rakhmerov): We can avoid hitting DB at all when calling something # create_action_execution(), these operations can be just done using # SQLAlchemy session (1-level cache) and session flush (on TX commit) would # send necessary SQL queries to DB. Currently, session flush happens # on every operation which may not be optimal. The problem with using just # session level cache is in generating ids. Ids are generated only on # session flush. And now we have a lot places where we need to have ids # before TX completion. # Assign the action execution ID here to minimize database calls. # Otherwise, the input property of the action execution DB object needs # to be updated with the action execution ID after the action execution # DB object is created. action_ex_id = utils.generate_unicode_uuid() if a_m.has_action_context(action_def.action_class, action_def.attributes or {}) and task_ex: action_input.update(a_m.get_action_context(task_ex, action_ex_id)) values = { 'id': action_ex_id, 'name': action_def.name, 'spec': action_def.spec, 'state': states.RUNNING, 'input': action_input, 'runtime_context': { 'with_items_index': index }, 'description': description } if task_ex: values.update({ 'task_execution_id': task_ex.id, 'workflow_name': task_ex.workflow_name, 'workflow_id': task_ex.workflow_id, 'project_id': task_ex.project_id, }) else: values.update({ 'project_id': security.get_project_id(), }) action_ex = db_api.create_action_execution(values) if task_ex: # Add to collection explicitly so that it's in a proper # state within the current session. task_ex.executions.append(action_ex) return action_ex
def create_action_execution(action_def, action_input, task_ex=None, index=0, description=''): # TODO(rakhmerov): We can avoid hitting DB at all when calling something # create_action_execution(), these operations can be just done using # SQLAlchemy session (1-level cache) and session flush (on TX commit) would # send necessary SQL queries to DB. Currently, session flush happens # on every operation which may not be optimal. The problem with using just # session level cache is in generating ids. Ids are generated only on # session flush. And now we have a lot places where we need to have ids # before TX completion. # Assign the action execution ID here to minimize database calls. # Otherwise, the input property of the action execution DB object needs # to be updated with the action execution ID after the action execution # DB object is created. action_ex_id = utils.generate_unicode_uuid() if a_m.has_action_context( action_def.action_class, action_def.attributes or {}) and task_ex: action_input.update(a_m.get_action_context(task_ex, action_ex_id)) values = { 'id': action_ex_id, 'name': action_def.name, 'spec': action_def.spec, 'state': states.RUNNING, 'input': action_input, 'runtime_context': {'with_items_index': index}, 'description': description } if task_ex: values.update({ 'task_execution_id': task_ex.id, 'workflow_name': task_ex.workflow_name, 'workflow_id': task_ex.workflow_id, 'project_id': task_ex.project_id, }) else: values.update({ 'project_id': security.get_project_id(), }) action_ex = db_api.create_action_execution(values) if task_ex: # Add to collection explicitly so that it's in a proper # state within the current session. task_ex.executions.append(action_ex) return action_ex
def _insert_action_context(self, action_ex_id, input_dict, save=True): """Template method to prepare action context. It inserts the action context in the input if required runtime context. """ # we need to push action context to all actions. It's related to # https://blueprints.launchpad.net/mistral/+spec/mistral-custom-actions-api has_action_context = a_m.has_action_context( self.action_def.action_class, self.action_def.attributes or {}) if has_action_context: input_dict.update( a_m.get_action_context(self.task_ex, action_ex_id, save=save))
def _insert_action_context(self, action_ex_id, input_dict, save=True): """Template method to prepare action context. It inserts the action context in the input if required runtime context. """ # we need to push action context to all actions. It's related to # https://blueprints.launchpad.net/mistral/+spec/mistral-custom-actions-api has_action_context = a_m.has_action_context( self.action_def.action_class, self.action_def.attributes or {} ) if has_action_context: input_dict.update( a_m.get_action_context(self.task_ex, action_ex_id, save=save) )
def _create_action_execution(self, input_dict, runtime_ctx, desc=''): # Assign the action execution ID here to minimize database calls. # Otherwise, the input property of the action execution DB object needs # to be updated with the action execution ID after the action execution # DB object is created. action_ex_id = utils.generate_unicode_uuid() # TODO(rakhmerov): Bad place, we probably need to push action context # to all actions. It's related to # https://blueprints.launchpad.net/mistral/+spec/mistral-custom-actions-api if a_m.has_action_context( self.action_def.action_class, self.action_def.attributes or {}) and self.task_ex: input_dict.update( a_m.get_action_context(self.task_ex, action_ex_id) ) values = { 'id': action_ex_id, 'name': self.action_def.name, 'spec': self.action_def.spec, 'state': states.RUNNING, 'input': input_dict, 'runtime_context': runtime_ctx, 'description': desc } if self.task_ex: values.update({ 'task_execution_id': self.task_ex.id, 'workflow_name': self.task_ex.workflow_name, 'workflow_id': self.task_ex.workflow_id, 'project_id': self.task_ex.project_id, }) else: values.update({ 'project_id': security.get_project_id(), }) self.action_ex = db_api.create_action_execution(values) if self.task_ex: # Add to collection explicitly so that it's in a proper # state within the current session. self.task_ex.executions.append(self.action_ex)