def on_action_complete(self, action_ex_id, result): with db_api.transaction(): action_ex = db_api.get_action_execution(action_ex_id) task_ex = action_ex.task_execution if task_ex: wf_handler.lock_workflow_execution( task_ex.workflow_execution_id) action_handler.on_action_complete(action_ex, result) return action_ex.get_clone()
def on_action_complete(self, action_ex_id, result): wf_ex_id = None try: with db_api.transaction(): action_ex = db_api.get_action_execution(action_ex_id) # In case of single action execution there is no # assigned task execution. if not action_ex.task_execution: return action_handler.store_action_result( action_ex, result).get_clone() wf_ex_id = action_ex.task_execution.workflow_execution_id wf_ex = wf_handler.lock_workflow_execution(wf_ex_id) task_ex = task_handler.on_action_complete(action_ex, result) # If workflow is on pause or completed then there's no # need to continue workflow. if states.is_paused_or_completed(wf_ex.state): return action_ex.get_clone() prev_task_state = task_ex.state # Separate the task transition in a separate transaction. The task # has already completed for better or worst. The task state should # not be affected by errors during transition on conditions such as # on-success and on-error. with db_api.transaction(): wf_ex = wf_handler.lock_workflow_execution(wf_ex_id) action_ex = db_api.get_action_execution(action_ex_id) task_ex = action_ex.task_execution self._on_task_state_change(task_ex, wf_ex, task_state=prev_task_state) return action_ex.get_clone() except Exception as e: # TODO(dzimine): try to find out which command caused failure. # TODO(rakhmerov): Need to refactor logging in a more elegant way. LOG.error( "Failed to handle action execution result [id=%s]: %s\n%s", action_ex_id, e, traceback.format_exc()) # If an exception was thrown after we got the wf_ex_id if wf_ex_id: self._fail_workflow(wf_ex_id, e) raise e
def on_action_complete(self, action_ex_id, result): with db_api.transaction(): action_ex = db_api.get_action_execution(action_ex_id) task_ex = action_ex.task_execution if task_ex: wf_handler.lock_workflow_execution( task_ex.workflow_execution_id ) action_handler.on_action_complete(action_ex, result) return action_ex.get_clone()
def pause_workflow(self, execution_id): with db_api.transaction(): wf_ex = wf_handler.lock_workflow_execution(execution_id) wf_handler.set_execution_state(wf_ex, states.PAUSED) return wf_ex
def pause_workflow(self, wf_ex_id): with db_api.transaction(): wf_ex = wf_handler.lock_workflow_execution(wf_ex_id) wf_handler.pause_workflow(wf_ex) return wf_ex.get_clone()
def pause_workflow(self, wf_ex_id): with db_api.transaction(): wf_ex = wf_handler.lock_workflow_execution(wf_ex_id) wf_handler.set_execution_state(wf_ex, states.PAUSED) return wf_ex
def resume_workflow(self, wf_ex_id, env=None): with db_api.transaction(): wf_ex = wf_handler.lock_workflow_execution(wf_ex_id) wf_handler.resume_workflow(wf_ex, env=env) return wf_ex.get_clone()
def stop_workflow(self, wf_ex_id, state, message=None): with db_api.transaction(): wf_ex = wf_handler.lock_workflow_execution(wf_ex_id) wf_handler.stop_workflow(wf_ex, state, message) return wf_ex.get_clone()
def pause_workflow(self, wf_ex_id): with db_api.transaction(): wf_ex = wf_handler.lock_workflow_execution(wf_ex_id) wf_handler.pause_workflow(wf_ex) return wf_ex.get_clone()
def stop_workflow(self, wf_ex_id, state, message=None): with db_api.transaction(): wf_ex = wf_handler.lock_workflow_execution(wf_ex_id) wf_handler.stop_workflow(wf_ex, state, message) return wf_ex.get_clone()
def resume_workflow(self, wf_ex_id, env=None): with db_api.transaction(): wf_ex = wf_handler.lock_workflow_execution(wf_ex_id) wf_handler.resume_workflow(wf_ex, env=env) return wf_ex.get_clone()
def resume_workflow(self, wf_ex_id, env=None): # TODO(rakhmerov): Rewrite this functionality with Task abstraction. with db_api.transaction(): wf_ex = wf_handler.lock_workflow_execution(wf_ex_id) if (not states.is_paused(wf_ex.state) and not states.is_idle(wf_ex.state)): return wf_ex.get_clone() return self._continue_workflow(wf_ex, env=env)
def rerun_workflow(self, task_ex_id, reset=True, env=None): with db_api.transaction(): task_ex = db_api.get_task_execution(task_ex_id) wf_ex = wf_handler.lock_workflow_execution( task_ex.workflow_execution_id) wf_handler.rerun_workflow(wf_ex, task_ex, reset=reset, env=env) return wf_ex.get_clone()
def rerun_workflow(self, task_ex_id, reset=True, env=None): with db_api.transaction(): task_ex = db_api.get_task_execution(task_ex_id) wf_ex = wf_handler.lock_workflow_execution( task_ex.workflow_execution_id ) wf_handler.rerun_workflow(wf_ex, task_ex, reset=reset, env=env) return wf_ex.get_clone()
def rerun_workflow(self, wf_ex_id, task_ex_id, reset=True, env=None): # TODO(rakhmerov): Rewrite this functionality with Task abstraction. with db_api.transaction(): wf_ex = wf_handler.lock_workflow_execution(wf_ex_id) task_ex = db_api.get_task_execution(task_ex_id) if task_ex.workflow_execution.id != wf_ex_id: raise ValueError('Workflow execution ID does not match.') if wf_ex.state == states.PAUSED: return wf_ex.get_clone() # TODO(rakhmerov): This should be a call to workflow handler. return self._continue_workflow(wf_ex, task_ex, reset, env=env)
def resume_workflow(self, wf_ex_id, env=None): try: with db_api.transaction(): wf_ex = wf_handler.lock_workflow_execution(wf_ex_id) if (not states.is_paused(wf_ex.state) and not states.is_idle(wf_ex.state)): return wf_ex.get_clone() return self._continue_workflow(wf_ex, env=env) except Exception as e: LOG.error("Failed to resume execution id=%s: %s\n%s", wf_ex_id, e, traceback.format_exc()) self._fail_workflow(wf_ex_id, e) raise e
def on_action_complete(self, action_ex_id, result): wf_ex_id = None try: with db_api.transaction(): action_ex = db_api.get_action_execution(action_ex_id) # In case of single action execution there is no # assigned task execution. if not action_ex.task_execution: return action_handler.store_action_result( action_ex, result ).get_clone() wf_ex_id = action_ex.task_execution.workflow_execution_id wf_ex = wf_handler.lock_workflow_execution(wf_ex_id) wf_spec = spec_parser.get_workflow_spec(wf_ex.spec) task_ex = task_handler.on_action_complete( action_ex, wf_spec, result ) # If workflow is on pause or completed then there's no # need to continue workflow. if states.is_paused_or_completed(wf_ex.state): return action_ex.get_clone() self._on_task_state_change(task_ex, wf_ex, wf_spec) return action_ex.get_clone() except Exception as e: # TODO(rakhmerov): Need to refactor logging in a more elegant way. LOG.error( 'Failed to handle action execution result [id=%s]: %s\n%s', action_ex_id, e, traceback.format_exc() ) # If an exception was thrown after we got the wf_ex_id if wf_ex_id: self._fail_workflow(wf_ex_id, e) raise e
def resume_workflow(self, wf_ex_id, env=None): try: with db_api.transaction(): wf_ex = wf_handler.lock_workflow_execution(wf_ex_id) if (not states.is_paused(wf_ex.state) and not states.is_idle(wf_ex.state)): return wf_ex.get_clone() return self._continue_workflow(wf_ex, env=env) except Exception as e: LOG.error( "Failed to resume execution id=%s: %s\n%s", wf_ex_id, e, traceback.format_exc() ) self._fail_workflow(wf_ex_id, e) raise e
def on_task_state_change(self, task_ex_id, state, state_info=None): with db_api.transaction(): task_ex = db_api.get_task_execution(task_ex_id) # TODO(rakhmerov): The method is mostly needed for policy and # we are supposed to get the same action execution as when the # policy worked. wf_ex_id = task_ex.workflow_execution_id wf_ex = wf_handler.lock_workflow_execution(wf_ex_id) wf_trace.info( task_ex, "Task '%s' [%s -> %s] state_info : %s" % (task_ex.name, task_ex.state, state, state_info)) task_ex.state = state task_ex.state_info = state_info self._on_task_state_change(task_ex, wf_ex)
def _fail_workflow(wf_ex_id, exc): """Private helper to fail workflow on exceptions.""" with db_api.transaction(): wf_ex = db_api.load_workflow_execution(wf_ex_id) if wf_ex is None: LOG.error( "Can't fail workflow execution with id='%s': not found.", wf_ex_id ) return None wf_ex = wf_handler.lock_workflow_execution(wf_ex_id) if not states.is_paused_or_completed(wf_ex.state): wf_handler.set_execution_state(wf_ex, states.ERROR, str(exc)) return wf_ex
def rerun_workflow(self, wf_ex_id, task_ex_id, reset=True, env=None): try: with db_api.transaction(): wf_ex = wf_handler.lock_workflow_execution(wf_ex_id) task_ex = db_api.get_task_execution(task_ex_id) if task_ex.workflow_execution.id != wf_ex_id: raise ValueError('Workflow execution ID does not match.') if wf_ex.state == states.PAUSED: return wf_ex.get_clone() return self._continue_workflow(wf_ex, task_ex, reset, env=env) except Exception as e: LOG.error("Failed to rerun execution id=%s at task=%s: %s\n%s", wf_ex_id, task_ex_id, e, traceback.format_exc()) self._fail_workflow(wf_ex_id, e) raise e
def on_task_state_change(self, task_ex_id, state, state_info=None): with db_api.transaction(): task_ex = db_api.get_task_execution(task_ex_id) # TODO(rakhmerov): The method is mostly needed for policy and # we are supposed to get the same action execution as when the # policy worked. wf_ex_id = task_ex.workflow_execution_id wf_ex = wf_handler.lock_workflow_execution(wf_ex_id) wf_spec = spec_parser.get_workflow_spec(wf_ex.spec) wf_trace.info( task_ex, "Task '%s' [%s -> %s] state_info : %s" % (task_ex.name, task_ex.state, state, state_info) ) task_ex.state = state task_ex.state_info = state_info self._on_task_state_change(task_ex, wf_ex, wf_spec)
def rerun_workflow(self, wf_ex_id, task_ex_id, reset=True, env=None): try: with db_api.transaction(): wf_ex = wf_handler.lock_workflow_execution(wf_ex_id) task_ex = db_api.get_task_execution(task_ex_id) if task_ex.workflow_execution.id != wf_ex_id: raise ValueError('Workflow execution ID does not match.') if wf_ex.state == states.PAUSED: return wf_ex.get_clone() return self._continue_workflow(wf_ex, task_ex, reset, env=env) except Exception as e: LOG.error( "Failed to rerun execution id=%s at task=%s: %s\n%s", wf_ex_id, task_ex_id, e, traceback.format_exc() ) self._fail_workflow(wf_ex_id, e) raise e
def stop_workflow(self, execution_id, state, message=None): with db_api.transaction(): wf_ex = wf_handler.lock_workflow_execution(execution_id) return self._stop_workflow(wf_ex, state, message)