#NEWLINE# def collect_events( ) : #NEWLINE# #INDENT# '\n    Collect all events waiting in the queue and store them in the database.\n    ' #NEWLINE# consumer = None #NEWLINE# collection = None #NEWLINE# try : #NEWLINE# #INDENT# consumer = _get_carrot_object ( Consumer , queue = settings . QUEUE ) #NEWLINE# collection = models . get_mongo_collection ( ) #NEWLINE# for message in consumer . iterqueue ( ) : #NEWLINE# #INDENT# ( e , t , p ) = message . decode ( ) #NEWLINE# models . save_event ( collection , e , t , p ) #NEWLINE# message . ack ( ) #NEWLINE# #UNINDENT# #UNINDENT# finally : #NEWLINE# #INDENT# _close_carrot_object ( consumer ) #NEWLINE# if collection : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# collection . connection . close ( ) #NEWLINE# #UNINDENT# except : #NEWLINE# #INDENT# pass