#NEWLINE# def delay_for( self , service ) : #NEWLINE# #INDENT# 'This method is a public interface for a throttle storage class' #NEWLINE# _now = now ( ) #NEWLINE# limit = '{0}_limit' . format ( service ) #NEWLINE# self . prune ( ) #NEWLINE# sql = 'SELECT * FROM throttle_history ORDER BY {0} limit 1' . format ( limit ) #NEWLINE# with self . db : #NEWLINE# #INDENT# r = self . db . execute ( sql ) . fetchone ( ) #NEWLINE# #UNINDENT# if ( not r ) : #NEWLINE# #INDENT# next_run = _now #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( r [ limit ] == 0 ) : #NEWLINE# #INDENT# next_run = ( r [ 'timestamp' ] + timedelta ( milliseconds = r [ '{0}_retry_after' . format ( service ) ] ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# next_run = ( _now + timedelta ( seconds = ( 60.0 / r [ limit ] ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# td = ( next_run - _now ) #NEWLINE# ts = ( td . microseconds + ( ( td . seconds + ( ( td . days * 24 ) * 3600 ) ) * ( 10 ** 6 ) ) ) #NEWLINE# return ( ts / ( 10 ** 6 ) )