#NEWLINE# def wait_for_execution_to_end( execution , timeout_seconds = 240 ) : #NEWLINE# #INDENT# client = create_rest_client ( ) #NEWLINE# deadline = ( time . time ( ) + timeout_seconds ) #NEWLINE# while ( execution . status not in Execution . END_STATES ) : #NEWLINE# #INDENT# time . sleep ( 0.5 ) #NEWLINE# execution = client . executions . get ( execution . id ) #NEWLINE# if ( time . time ( ) > deadline ) : #NEWLINE# #INDENT# raise TimeoutException ( 'Execution timed out: \n{0}' . format ( json . dumps ( execution , indent = 2 ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( execution . status == Execution . FAILED ) : #NEWLINE# #INDENT# raise RuntimeError ( 'Workflow execution failed: {0} [{1}]' . format ( execution . error , execution . status ) ) #NEWLINE# #UNINDENT# return execution