Example #1
0
def collect_events():
    """
    Collect all events waiting in the queue and store them in the database.
    """    
    consumer = None
    collection = None
    backend_cls = _get_backend_cls()
    
    try:
        consumer = _get_carrot_object(Consumer, queue=settings.QUEUE)
        connection = Connection(host=settings.MONGODB_HOST, port=settings.MONGODB_PORT)

        for message in consumer.iterqueue():
            e, t, p, c = message.decode()
            backend_cls.save(event=e, time=t, params=p, collection=c)
            message.ack()

    finally:
        _close_carrot_object(consumer)
        if collection:
            try:
                collection.connection.close()
            except:
                pass
Example #2
0
 def track_event(self, event, params={}, collection=None):        
     backend = _get_backend_cls()
     return  backend.save(event, time(), params, collection)