#NEWLINE# def request_cancellation( liveaction , requester ) : #NEWLINE# #INDENT# '\n    Request cancellation of an action execution.\n\n    :return: (liveaction, execution)\n    :rtype: tuple\n    ' #NEWLINE# if ( liveaction . status == action_constants . LIVEACTION_STATUS_CANCELING ) : #NEWLINE# #INDENT# return liveaction #NEWLINE# #UNINDENT# if ( liveaction . status not in action_constants . LIVEACTION_CANCELABLE_STATES ) : #NEWLINE# #INDENT# raise Exception ( 'Unable to cancel execution because it is already in a completed state.' ) #NEWLINE# #UNINDENT# result = { #NEWLINE# #INDENT# 'message' : 'Action canceled by user.' , #NEWLINE# 'user' : requester , #NEWLINE# #UNINDENT# } #NEWLINE# status = ( action_constants . LIVEACTION_STATUS_CANCELING if ( liveaction . status == action_constants . LIVEACTION_STATUS_RUNNING ) else action_constants . LIVEACTION_STATUS_CANCELED ) #NEWLINE# update_status ( liveaction , status , result = result ) #NEWLINE# execution = ActionExecution . get ( liveaction__id = str ( liveaction . id ) ) #NEWLINE# return ( liveaction , execution )