#NEWLINE# @ app . task ( name = 'tasks.deferred_manual_cleanup' ) #NEWLINE# def deferred_manual_cleanup( model , limit_size = None , limit_days = None , limit_duplicated = None ) : #NEWLINE# #INDENT# logger = logging . getLogger ( 'limitation' ) #NEWLINE# full_result = dict ( count = 0 , size = 0 , elements = [ ] ) #NEWLINE# if limit_duplicated : #NEWLINE# #INDENT# result = delete_duplicate_crashes ( limit = limit_duplicated ) #NEWLINE# if result . get ( 'count' , 0 ) : #NEWLINE# #INDENT# full_result [ 'count' ] += result [ 'count' ] #NEWLINE# full_result [ 'size' ] += result [ 'size' ] #NEWLINE# full_result [ 'elements' ] += result [ 'elements' ] #NEWLINE# #UNINDENT# #UNINDENT# if limit_days : #NEWLINE# #INDENT# result = delete_older_than ( * model , limit = limit_days ) #NEWLINE# if result . get ( 'count' , 0 ) : #NEWLINE# #INDENT# full_result [ 'count' ] += result [ 'count' ] #NEWLINE# full_result [ 'size' ] += result [ 'size' ] #NEWLINE# full_result [ 'elements' ] += result [ 'elements' ] #NEWLINE# #UNINDENT# #UNINDENT# if limit_size : #NEWLINE# #INDENT# result = delete_size_is_exceeded ( * model , limit = limit_size ) #NEWLINE# if result . get ( 'count' , 0 ) : #NEWLINE# #INDENT# full_result [ 'count' ] += result [ 'count' ] #NEWLINE# full_result [ 'size' ] += result [ 'size' ] #NEWLINE# full_result [ 'elements' ] += result [ 'elements' ] #NEWLINE# #UNINDENT# #UNINDENT# full_result [ 'size' ] /= ( 1024.0 * 1024 ) #NEWLINE# log_id = str ( uuid . uuid4 ( ) ) #NEWLINE# params = dict ( log_id = log_id ) #NEWLINE# splunk_url = get_splunk_url ( params ) #NEWLINE# splunk_filter = ( ( 'log_id=%s' % log_id ) if splunk_url else None ) #NEWLINE# raven_extra = dict ( id = log_id , splunk_url = splunk_url , splunk_filter = splunk_filter ) #NEWLINE# raven . captureMessage ( ( '[Limitation]Manual cleanup freed %d %s, total size of cleaned space is %.2f Mb[%s]' % ( full_result [ 'count' ] , model [ 1 ] , full_result [ 'size' ] , log_id ) ) , data = dict ( level = 20 , logger = 'limitation' ) , extra = raven_extra ) #NEWLINE# extra = dict ( log_id = log_id , meta = True , count = full_result [ 'count' ] , size = full_result [ 'size' ] , model = model [ 1 ] , limit_duplicated = limit_duplicated , limit_size = limit_size , limit_days = limit_days , reason = 'manual' ) #NEWLINE# logger . info ( add_extra_to_log_message ( 'Manual cleanup' , extra = extra ) ) #NEWLINE# for element in full_result [ 'elements' ] : #NEWLINE# #INDENT# element . update ( dict ( log_id = log_id ) ) #NEWLINE# logger . info ( add_extra_to_log_message ( 'Manual cleanup element' , extra = element ) )