Exemplo n.º 1
0
def send_amq_results_ready():
    """
        Entry point for console script to send a results-ready message to AMQ
    """
    # Create a configuration object
    conf = Configuration()

    # Parse command arguments
    parser = argparse.ArgumentParser(description="Kepler workflow communication")
    parser.add_argument(
        conf.kepler_result_queue_flag,
        metavar="return_queue",
        required=True,
        help="AMQ queue to send results to",
        dest="return_queue",
    )
    parser.add_argument(
        conf.kepler_output_file_flag,
        metavar="output_file",
        default="results.out",
        help="Kepler output file",
        dest="output_file",
    )
    namespace = parser.parse_args()

    # Setup the AMQ client
    c = Client(conf.brokers, conf.amq_user, conf.amq_pwd)

    # Send a simple message to the return queue
    message = {"output_file": namespace.output_file}
    c.send(destination="/queue/" + namespace.return_queue, message=json.dumps(message))
    c._disconnect()

    send_status_info(str(os.getpid()), "stop_iteration")
Exemplo n.º 2
0
def run_kepler_client():
    """
        Entry point for kepler_client console script.
        Starts an AMQ client for Kepler.
    """
    # Set log level set up log file handler
    logging.getLogger().setLevel(logging.ERROR)
    ft = logging.Formatter("%(asctime)-15s %(message)s")
    fh = logging.FileHandler("kepler_job.log")
    fh.setLevel(logging.ERROR)
    fh.setFormatter(ft)
    logging.getLogger().addHandler(fh)

    # Create a configuration object
    conf = Configuration()
    logging.error(str(sys.argv))
    parser = argparse.ArgumentParser(description="Kepler workflow client")
    parser.add_argument(
        conf.kepler_params_queue_flag,
        metavar="params_queue",
        required=True,
        help="AMQ queue to receive new parameters from ",
        dest="params_queue",
    )
    namespace = parser.parse_args()

    params_queue = "%s.%s" % (conf.params_ready_queue, str(os.getpid()))

    logging.info("Parameter queue is %s" % namespace.params_queue)

    queues = [namespace.params_queue]
    c = KeplerJobClient(conf.brokers, conf.amq_user, conf.amq_pwd, queues, "kepler_consumer")
    c.set_params_ready_queue(namespace.params_queue)
    c.set_listener(KeplerJobListener(namespace.params_queue))
    send_status_info(str(os.getpid()), "start_iteration")
    c.listen_and_wait()