Beispiel #1
0
def tick():
    print('Tick! The time is: %s' % datetime.now())
    (connection, exchange) = get_mq_connection()
    data = get_resource_data()
    for each in data:
        print each
        send_mq_message_pconn(connection, exchange, each)
        save_to_mq_buffer(each['mq_uuid'], each)
Beispiel #2
0
def resend_mq():
    print('Info: Tick! The time is: %s' % datetime.now())
    from send_message import get_mq_connection, send_mq_message_pconn
    session = get_mysql_session("using")
    (connection, exchange) = get_mq_connection()

    resend = get_resending_resource_ids(session)
    for each in resend:
        resource_dict = get_resource_from_id(session, each['resource_id'])
        del resource_dict['created_at']
        del resource_dict['updated_at']
        del resource_dict['deleted_at']
        '''append item from   using table;'''
        resource_dict['using_id'] = each['using_id']
        resource_dict['started_at'] = each['started_at']
        resource_dict['ended_at'] = each['ended_at']

        #print "DDD %s"%resource_dict;
        send_mq_message_pconn(connection, exchange, resource_dict)
Beispiel #3
0
def collect_cdn_res():
    print('Start to collect  resource at %s' % datetime.now())
    (connection, exchange) = get_mq_connection()
    session = get_mysql_session("nova")
    data = get_cdn_resource_data()

    global count
    count = 0
    for each in data:
        print each
        count = count + 1
        send_mq_message_pconn(connection, exchange, each)
        save_to_resource_mq_buffer_pconn(session, each)
        save_to_using_mq_buffer_pconn(session, each['mq_uuid'],
                                      each['resource_id'])
        if count == 1024:
            session.commit()
            count = 0

    session.close()
    print('end of  collecting   resource at %s' % datetime.now())
Beispiel #4
0
        (connection, exchange)=get_mq_connection_ack();
        send_mq_message_ack_pconn(connection,exchange, ret);
        LOG.info("message_ack: %s send "%ret);
    else:
        LOG.info("ERROR: this msg have no using_id ");
    
def handle_message(body, message):
    global count;
    count=count+1;
    
    print(' Received message: %d %r' % (count,body ));
    LOG.info(' Received message: %d %r' % (count,body ));
    deal_with_message(body);
    message.ack()

    
if __name__=="__main__":
    log_init();

    global count;
    count=0
    from  send_message  import get_mq_connection;

    #with Connection('amqp://*****:*****@192.168.210.31:5672//') as connection:
    connection, exchange= get_mq_connection();
    queue = Queue('billing_collector', exchange, routing_key='billing_collector')
    with  connection:
        with Consumer(connection, queue, callbacks=[handle_message]):
            for _ in eventloop(connection):
                pass
Beispiel #5
0
        tmp['resource_type'] = "cdnbandwidth"
        tmp['sum'] = amount
        tmp['billing_item'] = "cdnbandwidth_1_M"
        tmp['status'] = "sending"
        resource = dict(header, **tmp)
        ret.append(resource)

    return ret


from send_message import send_mq_message_pconn, get_mq_connection

from kombu import Connection, Producer, Exchange, Queue

if __name__ == "__main__":
    (connection, exchange) = get_mq_connection()

    global count
    count = 0
    session = get_mysql_session("using")
    cdn_resource = get_cdn_resource_data()
    for each in cdn_resource:
        print each

        count = count + 1
        send_mq_message_pconn(connection, exchange, each)
        save_to_resource_mq_buffer_pconn(session, each)
        save_to_using_mq_buffer_pconn(session, each['mq_uuid'],
                                      each['resource_id'])
        if count % 1024 == 0:
            session.commit()