#NEWLINE# @ app . task ( bind = True ) #NEWLINE# @ only_one ( key = 'get_databases_used_size' , timeout = 180 ) #NEWLINE# def update_database_used_size( self ) : #NEWLINE# #INDENT# LOG . info ( 'Retrieving all databases' ) #NEWLINE# try : #NEWLINE# #INDENT# worker_name = get_worker_name ( ) #NEWLINE# task_history = TaskHistory . register ( request = self . request , user = None , worker_name = worker_name ) #NEWLINE# databases = Database . objects . all ( ) #NEWLINE# msgs = [ ] #NEWLINE# for database in databases : #NEWLINE# #INDENT# if database . database_status : #NEWLINE# #INDENT# database . used_size_in_bytes = float ( database . database_status . used_size_in_bytes ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# database . used_size_in_bytes = 0.0 #NEWLINE# #UNINDENT# database . save ( update_fields = [ 'used_size_in_bytes' ] ) #NEWLINE# msg = '\nUpdating used size in bytes for database: {}, used size: {}' . format ( database , database . used_size_in_bytes ) #NEWLINE# msgs . append ( msg ) #NEWLINE# LOG . info ( msg ) #NEWLINE# #UNINDENT# task_history . update_status_for ( TaskHistory . STATUS_SUCCESS , details = '\n' . join ( ( value for value in msgs ) ) ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# task_history . update_status_for ( TaskHistory . STATUS_ERROR , details = e ) #NEWLINE# #UNINDENT# return