#NEWLINE# def monitor_query_queue( self , job_id , job_metadata , query_object = None , callback_function = None ) : #NEWLINE# #INDENT# query_object = ( query_object or self ) #NEWLINE# started_checking = datetime . datetime . utcnow ( ) #NEWLINE# notification_identifier = ', ' . join ( filter ( None , job_metadata . values ( ) ) ) #NEWLINE# self . logger . info ( 'Queued request for %s, received job id: %s' , notification_identifier , job_id ) #NEWLINE# while True : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# job_collection = query_object . _authenticated_service . jobs ( ) #NEWLINE# job_collection_state = job_collection . get ( projectId = self . _project_id , jobId = job_id ) . execute ( ) #NEWLINE# #UNINDENT# except ( SSLError , Exception , AttributeError , HttpError , httplib2 . ServerNotFoundError ) as caught_error : #NEWLINE# #INDENT# self . logger . warn ( 'Encountered error (%s) monitoring for %s, could be temporary, not bailing out.' , caught_error , notification_identifier ) #NEWLINE# job_collection_state = None #NEWLINE# #UNINDENT# if ( job_collection_state is not None ) : #NEWLINE# #INDENT# time_waiting = int ( ( datetime . datetime . utcnow ( ) - started_checking ) . total_seconds ( ) ) #NEWLINE# if ( job_collection_state [ 'status' ] [ 'state' ] == 'RUNNING' ) : #NEWLINE# #INDENT# self . logger . info ( 'Waiting for %s to complete, spent %d seconds so far.' , notification_identifier , notification_identifier ) #NEWLINE# time . sleep ( 10 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( job_collection_state [ 'status' ] [ 'state' ] == 'PENDING' ) : #NEWLINE# #INDENT# self . logger . info ( 'Waiting for %s to submit, spent %d seconds so far.' , notification_identifier , time_waiting ) #NEWLINE# time . sleep ( 60 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( job_collection_state [ 'status' ] [ 'state' ] == 'DONE' ) and ( callback_function is not None ) ) : #NEWLINE# #INDENT# self . logger . info ( 'Found completion status for %s.' , notification_identifier ) #NEWLINE# callback_function ( job_id , query_object = self ) #NEWLINE# break #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise Exception ( 'UnknownBigQueryResponse' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return None