Exemple #1
0
def worker(rabbit_cfg, function):
    f = FunctionWrapper(
        function['module_path'], 
        function['module_name'], 
        function['function_name']
    )
    r = Rabbit(
        function=f,
        exchange=function['exchange'],
        queue=function['queue'], 
        routing_key=function.get('routing_key'),
        host=rabbit_cfg.get('host'),
        port=rabbit_cfg.get('port'),
        userid=rabbit_cfg.get('userid'),
        password=rabbit_cfg.get('password'),
        durable=rabbit_cfg.get('durable', True)
    )
    r.connect()
    r.declare()
    r.consume()
Exemple #2
0
        stop = stop_job(jd)
        time.sleep(2)
        start = start_job(jd)
        logger.critical(
            "Tool just returned the main source by stop and start job: Job(%s)"
            % (str(data)))
    return 0


def callback(ch, method, properties, body):
    date_time = DateTime()
    print "------------->\n" + str(date_time.get_now_as_human_creadeble(
    )) + " recieved: " + body + "\n<-------------"
    logger.info("received " + body)
    if not body:
        logger.warning("received " + body + "empty!")
        return 1
    t = threading.Thread(target=return_main, args=(body, ))
    t.start()


if __name__ == "__main__":
    rb = Rabbit(SYSTEM["RUNNING_BACKUP_QUEUE"])
    rb.connect()
    rb.channel.basic_consume(callback, queue=rb.routing_key, no_ack=True)

    print(' [*] Waiting for messages. To exit press CTRL+C')
    rb.channel.start_consuming()
    #data = """{"host":"172.17.5.110", "jid": 1100}"""
    #print return_main(data)