def request_resume(liveaction, requester): """ Request resume for a paused action execution. :return: (liveaction, execution) :rtype: tuple """ # Validate that the runner type of the action supports pause. action_db = action_utils.get_action_by_ref(liveaction.action) if not action_db: raise ValueError( 'Unable to resume liveaction "%s" because the action "%s" ' "is not found." % (liveaction.id, liveaction.action)) if action_db.runner_type[ "name"] not in action_constants.WORKFLOW_RUNNER_TYPES: raise runner_exc.InvalidActionRunnerOperationError( 'Unable to resume liveaction "%s" because it is not supported by the ' '"%s" runner.' % (liveaction.id, action_db.runner_type["name"])) running_states = [ action_constants.LIVEACTION_STATUS_RUNNING, action_constants.LIVEACTION_STATUS_RESUMING, ] if liveaction.status in running_states: execution = ActionExecution.get(liveaction__id=str(liveaction.id)) return (liveaction, execution) if liveaction.status != action_constants.LIVEACTION_STATUS_PAUSED: raise runner_exc.UnexpectedActionExecutionStatusError( 'Unable to resume liveaction "%s" because it is in "%s" state and ' 'not in "paused" state.' % (liveaction.id, liveaction.status)) liveaction.context["resumed_by"] = get_requester(requester) liveaction = update_status( liveaction, action_constants.LIVEACTION_STATUS_RESUMING, context=liveaction.context, ) execution = ActionExecution.get(liveaction__id=str(liveaction.id)) return (liveaction, execution)
def request_pause(liveaction, requester): """ Request pause for a running action execution. :return: (liveaction, execution) :rtype: tuple """ # Validate that the runner type of the action supports pause. action_db = action_utils.get_action_by_ref(liveaction.action) if not action_db: raise ValueError( 'Unable to pause liveaction "%s" because the action "%s" ' "is not found." % (liveaction.id, liveaction.action) ) if action_db.runner_type["name"] not in action_constants.WORKFLOW_RUNNER_TYPES: raise runner_exc.InvalidActionRunnerOperationError( 'Unable to pause liveaction "%s" because it is not supported by the ' '"%s" runner.' % (liveaction.id, action_db.runner_type["name"]) ) if ( liveaction.status == action_constants.LIVEACTION_STATUS_PAUSING or liveaction.status == action_constants.LIVEACTION_STATUS_PAUSED ): execution = ActionExecution.get(liveaction__id=str(liveaction.id)) return (liveaction, execution) if liveaction.status != action_constants.LIVEACTION_STATUS_RUNNING: raise runner_exc.UnexpectedActionExecutionStatusError( 'Unable to pause liveaction "%s" because it is not in a running state.' % liveaction.id ) liveaction = update_status(liveaction, action_constants.LIVEACTION_STATUS_PAUSING) execution = ActionExecution.get(liveaction__id=str(liveaction.id)) return (liveaction, execution)