#NEWLINE# def put( self , **kwargs ) : #NEWLINE# #INDENT# deploy = self . _get_deploy ( ** kwargs ) #NEWLINE# if ( deploy is None ) : #NEWLINE# #INDENT# return self . error ( 'Invalid deploy' , name = 'invalid_resource' , status_code = 404 ) #NEWLINE# #UNINDENT# with lock ( redis , 'deploy:{}' . format ( deploy . id ) , timeout = 5 ) : #NEWLINE# #INDENT# deploy = Deploy . query . get ( deploy . id ) #NEWLINE# task = Task . query . get ( deploy . task_id ) #NEWLINE# args = self . put_parser . parse_args ( ) #NEWLINE# if args . status : #NEWLINE# #INDENT# assert ( task . status in ( TaskStatus . pending , TaskStatus . in_progress ) ) #NEWLINE# assert ( args . status == 'cancelled' ) #NEWLINE# did_cancel = ( task . status == TaskStatus . pending ) #NEWLINE# task . status = TaskStatus . cancelled #NEWLINE# #UNINDENT# db . session . add ( kwargs ) #NEWLINE# db . session . commit ( ) #NEWLINE# #UNINDENT# if ( args . status and did_cancel ) : #NEWLINE# #INDENT# send_task_notifications ( task , NotifierEvent . TASK_FINISHED ) #NEWLINE# #UNINDENT# return self . respond ( serialize ( deploy ) )