def on_action_complete(self, action_ex): assert self.task_ex # TODO(rakhmerov): Here we can define more informative messages # cases when action is successful and when it's not. For example, # in state_info we can specify the cause action. # The use of action_ex.output.get('result') for state_info is not # accurate because there could be action executions that had # failed or was cancelled prior to this action execution. state_info = { states.SUCCESS: None, states.ERROR: 'One or more action executions had failed.', states.CANCELLED: 'One or more action executions was cancelled.' } with_items.increase_capacity(self.task_ex) if with_items.is_completed(self.task_ex): state = with_items.get_final_state(self.task_ex) self.complete(state, state_info[state]) return if (with_items.has_more_iterations(self.task_ex) and with_items.get_concurrency(self.task_ex)): self._schedule_actions()
def on_action_complete(self, action_ex): assert self.task_ex state = action_ex.state # TODO(rakhmerov): Here we can define more informative messages # cases when action is successful and when it's not. For example, # in state_info we can specify the cause action. # The use of action_ex.output.get('result') for state_info is not # accurate because there could be action executions that had # failed or was cancelled prior to this action execution. state_info = { states.SUCCESS: None, states.ERROR: 'One or more action executions had failed.', states.CANCELLED: 'One or more action executions was cancelled.' } with_items.increase_capacity(self.task_ex) if with_items.is_completed(self.task_ex): state = with_items.get_final_state(self.task_ex) self.complete(state, state_info[state]) return if (with_items.has_more_iterations(self.task_ex) and with_items.get_concurrency(self.task_ex)): self._schedule_actions()
def on_action_complete(action_ex, wf_spec, result): """Handles event of action result arrival. Given action result this method changes corresponding task execution object. This method must never be called for the case of individual action which is not associated with any tasks. :param action_ex: Action execution objects the result belongs to. :param wf_spec: Workflow specification. :param result: Task action/workflow output wrapped into mistral.workflow.utils.Result instance. :return Task execution object. """ task_ex = action_ex.task_execution # Ignore if action already completed. if (states.is_completed(action_ex.state) and not isinstance(action_ex, models.WorkflowExecution)): return task_ex task_spec = wf_spec.get_tasks()[task_ex.name] try: result = action_handler.transform_result(result, task_ex, task_spec) except exc.YaqlEvaluationException as e: err_msg = str(e) LOG.error( 'YAQL error while transforming action result' ' [action_execution_id=%s, result=%s]: %s', action_ex.id, result, err_msg) result = wf_utils.Result(error=err_msg) # Ignore workflow executions because they're handled during # workflow completion. if not isinstance(action_ex, models.WorkflowExecution): action_handler.store_action_result(action_ex, result) if result.is_success(): task_state = states.SUCCESS task_state_info = None else: task_state = states.ERROR task_state_info = result.error if not task_spec.get_with_items(): _complete_task(task_ex, task_spec, task_state, task_state_info) else: with_items.increase_capacity(task_ex) if with_items.is_completed(task_ex): _complete_task(task_ex, task_spec, with_items.get_final_state(task_ex), task_state_info) return task_ex
def on_action_complete(action_ex, result): """Handles event of action result arrival. Given action result this method performs analysis of the workflow execution and identifies commands (including tasks) that can be scheduled for execution. :param action_ex: Action execution objects the result belongs to. :param result: Task action/workflow output wrapped into mistral.workflow.utils.Result instance. :return List of engine commands that need to be performed. """ task_ex = action_ex.task_execution # Ignore if action already completed. if (states.is_completed(action_ex.state) and not isinstance(action_ex, models.WorkflowExecution)): return task_ex result = action_handler.transform_result(result, task_ex) wf_ex = task_ex.workflow_execution # Ignore workflow executions because they're handled during # workflow completion. if not isinstance(action_ex, models.WorkflowExecution): action_handler.store_action_result(action_ex, result) wf_spec = spec_parser.get_workflow_spec(wf_ex.spec) task_spec = wf_spec.get_tasks()[task_ex.name] if result.is_success(): task_state = states.SUCCESS task_state_info = None else: task_state = states.ERROR task_state_info = result.error if not task_spec.get_with_items(): _complete_task(task_ex, task_spec, task_state, task_state_info) else: with_items.increase_capacity(task_ex) if with_items.is_completed(task_ex): _complete_task( task_ex, task_spec, with_items.get_final_state(task_ex), task_state_info ) return task_ex
def on_action_complete(action_ex, result): """Handles event of action result arrival. Given action result this method performs analysis of the workflow execution and identifies commands (including tasks) that can be scheduled for execution. :param action_ex: Action execution objects the result belongs to. :param result: Task action/workflow output wrapped into mistral.workflow.utils.Result instance. :return List of engine commands that need to be performed. """ task_ex = action_ex.task_execution # Ignore if action already completed. if (states.is_completed(action_ex.state) and not isinstance(action_ex, models.WorkflowExecution)): return task_ex result = action_handler.transform_result(result, task_ex) wf_ex = task_ex.workflow_execution # Ignore workflow executions because they're handled during # workflow completion. if not isinstance(action_ex, models.WorkflowExecution): action_handler.store_action_result(action_ex, result) wf_spec = spec_parser.get_workflow_spec(wf_ex.spec) task_spec = wf_spec.get_tasks()[task_ex.name] task_state = states.SUCCESS if result.is_success() else states.ERROR if not task_spec.get_with_items(): _complete_task(task_ex, task_spec, task_state) else: with_items.increase_capacity(task_ex) if with_items.is_completed(task_ex): _complete_task( task_ex, task_spec, with_items.get_final_state(task_ex) ) return task_ex
def on_action_complete(self, action_ex): state = action_ex.state # TODO(rakhmerov): Here we can define more informative messages # cases when action is successful and when it's not. For example, # in state_info we can specify the cause action. state_info = (None if state == states.SUCCESS else action_ex.output.get('result')) with_items.increase_capacity(self.task_ex) if with_items.is_completed(self.task_ex): self.complete( with_items.get_final_state(self.task_ex), state_info ) return if (with_items.has_more_iterations(self.task_ex) and with_items.get_concurrency(self.task_ex)): self._schedule_actions()
def is_task_completed(task_ex, task_spec): if task_spec.get_with_items(): return with_items.is_completed(task_ex) return states.is_completed(task_ex.state)
def on_action_complete(action_ex, wf_spec, result): """Handles event of action result arrival. Given action result this method changes corresponding task execution object. This method must never be called for the case of individual action which is not associated with any tasks. :param action_ex: Action execution objects the result belongs to. :param wf_spec: Workflow specification. :param result: Task action/workflow output wrapped into mistral.workflow.utils.Result instance. :return Task execution object. """ task_ex = action_ex.task_execution # Ignore if action already completed. if (states.is_completed(action_ex.state) and not isinstance(action_ex, models.WorkflowExecution)): return task_ex task_spec = wf_spec.get_tasks()[task_ex.name] try: result = action_handler.transform_result(result, task_ex, task_spec) except exc.YaqlEvaluationException as e: err_msg = str(e) LOG.error( 'YAQL error while transforming action result' ' [action_execution_id=%s, result=%s]: %s', action_ex.id, result, err_msg ) result = wf_utils.Result(error=err_msg) # Ignore workflow executions because they're handled during # workflow completion. if not isinstance(action_ex, models.WorkflowExecution): action_handler.store_action_result(action_ex, result) if result.is_success(): task_state = states.SUCCESS task_state_info = None else: task_state = states.ERROR task_state_info = result.error if not task_spec.get_with_items(): _complete_task(task_ex, task_spec, task_state, task_state_info) else: with_items.increase_capacity(task_ex) if with_items.is_completed(task_ex): _complete_task( task_ex, task_spec, with_items.get_final_state(task_ex), task_state_info ) return task_ex