#NEWLINE# def _run_heartbeat_manager( self ) : #NEWLINE# #INDENT# while self . thread_manager . running : #NEWLINE# #INDENT# contracts_to_submit = self . submission_queue . get ( ) #NEWLINE# if ( len ( contracts_to_submit ) > 0 ) : #NEWLINE# #INDENT# self . logger . info ( 'Submitting {0} contracts' . format ( len ( contracts_to_submit ) ) ) #NEWLINE# self . _submit_async ( contracts_to_submit ) #NEWLINE# #UNINDENT# contracts_to_update = self . update_queue . get ( ) #NEWLINE# if ( len ( contracts_to_update ) > 0 ) : #NEWLINE# #INDENT# self . logger . info ( 'Updating {0} contracts' . format ( len ( contracts_to_update ) ) ) #NEWLINE# self . _update_async ( contracts_to_update ) #NEWLINE# #UNINDENT# self . thread_manager . stats . set ( 'updating' , self . updating_counter . count ) #NEWLINE# self . thread_manager . stats . set ( 'submitting' , self . submitting_counter . count ) #NEWLINE# self . thread_manager . stats . set ( 'proving' , self . proving_counter . count ) #NEWLINE# worker_load = '{0}%' . format ( round ( ( self . worker_pool . calculate_loading ( ) * 100.0 ) , 3 ) ) #NEWLINE# worker_count = self . worker_pool . thread_count ( ) #NEWLINE# max_load = '{0}%' . format ( round ( ( self . worker_pool . max_load ( ) * 100.0 ) , 3 ) ) #NEWLINE# self . thread_manager . stats . set ( 'worker_threads' , worker_count ) #NEWLINE# self . thread_manager . stats . set ( 'avg_load' , worker_load ) #NEWLINE# self . thread_manager . stats . set ( 'max_load' , max_load ) #NEWLINE# next = [ self . submission_queue . next_due ( ) , self . update_queue . next_due ( ) ] #NEWLINE# next = [ n for n in next if ( n is not None ) ] #NEWLINE# if ( len ( next ) > 0 ) : #NEWLINE# #INDENT# seconds_to_sleep = ( min ( next ) - datetime . utcnow ( ) ) . total_seconds ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# seconds_to_sleep = None #NEWLINE# #UNINDENT# self . thread_manager . sleep ( seconds_to_sleep )