Exemplo n.º 1
0
def test_save_event_inserts_into_collection():
    collection = Mock()
    t = time()
    save_event(collection, sentinel.event, t, sentinel.params)

    tools.assert_equals(1, len(collection.method_calls))
    method, args, kwargs = collection.method_calls[0]
    tools.assert_equals('insert', method)
    tools.assert_equals(1, len(args))
    tools.assert_equals({}, kwargs)
    tools.assert_equals(sentinel.params, args[0]['params'])
    tools.assert_equals(sentinel.event, args[0]['event'])
    tools.assert_equals(datetime.fromtimestamp(t), args[0]['timestamp'])
def test_save_event_inserts_into_collection():
    collection = Mock()
    t = time()
    save_event(collection, sentinel.event, t, sentinel.params)

    tools.assert_equals(1, len(collection.method_calls))
    method, args, kwargs = collection.method_calls[0]
    tools.assert_equals('insert', method)
    tools.assert_equals(1, len(args))
    tools.assert_equals({}, kwargs)
    tools.assert_equals(sentinel.params, args[0]['params'])
    tools.assert_equals(sentinel.event, args[0]['event'])
    tools.assert_equals(datetime.fromtimestamp(t), args[0]['timestamp'])
Exemplo n.º 3
0
def collect_events(e, t, p):
    """
    Collect task waiting in the queue and store event in the database.
    """
    collection = None
    try:
        collection = models.get_mongo_collection()
        models.save_event(collection, e, t, p)

    finally:
        if collection:
            try:
                collection.connection.close()
            except:
                pass
Exemplo n.º 4
0
def collect_events(e, t, p):
    """
    Collect task waiting in the queue and store event in the database.
    """
    collection = None
    try:
        collection = models.get_mongo_collection()
        models.save_event(collection, e, t, p)

    finally:
        if collection:
            try:
                collection.connection.close()
            except:
                pass
Exemplo n.º 5
0
def collect_events():
    """
    Collect all events waiting in the queue and store them in the database.
    """
    consumer = None
    collection = None
    try:
        consumer = _get_carrot_object(Consumer, queue=settings.QUEUE)
        collection = models.get_mongo_collection()

        for message in consumer.iterqueue():
            e, t, p = message.decode()
            models.save_event(collection, e, t, p)
            message.ack()

    finally:
        _close_carrot_object(consumer)
        if collection:
            try:
                collection.connection.close()
            except:
                pass