@@ -0,0 +1,3215 @@
+#!/usr/bin/env python%0A%0Afrom amqp_service import log_formatter%0Aimport argparse%0Aimport json%0Aimport logging%0Aimport os%0Aimport pika%0Aimport uuid%0A%0ADEFAULT_AMQP_URL = 'amqp://guest:guest@localhost:5672/workflow'%0A%0ADEFAULT_LOG_LEVEL = logging.WARNING%0ALOG_FORMAT = ('%25(levelname)-23s %25(asctime)s %25(name)-60s %25(funcName)-45s'%0A              ' %25(lineno)5d: %25(message)s')%0ALOG = logging.getLogger()%0A%0A%0Adef parse():%0A    parser = argparse.ArgumentParser()%0A%0A    parser.add_argument('routing_key',%0A            help='What routing key to publish the message to')%0A    parser.add_argument('command_line', nargs='+',%0A            help='The command to run')%0A%0A    parser.add_argument('--log_level', type=int, default=DEFAULT_LOG_LEVEL)%0A    amqp_url_help = '%25s%5Cn%25s%5CnDefaults to %25s' %25 (%0A            'The location of the rabbitmq server.',%0A            'Overrides AMQP_URL environment variable.',%0A             DEFAULT_AMQP_URL)%0A    parser.add_argument('--amqp_url',%0A            default=os.getenv('AMQP_URL', DEFAULT_AMQP_URL),%0A            help=amqp_url_help)%0A%0A    parser.add_argument('--exchange', '-x', default='',%0A            help='Which exchange to send the job request to')%0A%0A    parser.add_argument('--exchange_type', '-t', default='direct',%0A            help='Which type of exchange to send the job request to')%0A%0A    parser.add_argument('--success_routing_key', '-s', default='fake.success')%0A    parser.add_argument('--failure_routing_key', '-f', default='fake.failure')%0A    parser.add_argument('--error_routing_key', '-e', default='fake.error')%0A%0A    default_return_identifier = uuid.uuid4().hex%0A    parser.add_argument('--return_identifier',%0A            default=default_return_identifier)%0A%0A    default_dir = os.getenv('HOME', '/tmp/service')%0A    parser.add_argument('--stdout',%0A            default=os.path.join(default_dir, 'out.log'))%0A    parser.add_argument('--stderr',%0A            default=os.path.join(default_dir, 'err.log'))%0A    parser.add_argument('--working_directory', '-d')%0A%0A    return parser.parse_args()%0A%0A%0Aif __name__ == '__main__':%0A    args = parse()%0A%0A    console_handler = logging.StreamHandler()%0A    console_handler.setFormatter(log_formatter.ColorFormatter(LOG_FORMAT))%0A    print args.log_level%0A    console_handler.setLevel(args.log_level)%0A    LOG.addHandler(console_handler)%0A    LOG.setLevel(args.log_level)%0A%0A    data = %7B%0A            'command_line': args.command_line,%0A            'return_identifier': args.return_identifier,%0A            'success_routing_key': args.success_routing_key,%0A            'failure_routing_key': args.failure_routing_key,%0A            'error_routing_key': args.error_routing_key,%0A            'stdout': args.stdout,%0A            'stderr': args.stderr,%0A            %7D%0A    if args.working_directory:%0A        LOG.debug('setting working_directory: %25s', args.working_directory)%0A        data%5B'working_directory'%5D = args.working_directory%0A%0A    message = json.dumps(data)%0A    LOG.debug('message assembled: %25s', message)%0A%0A    LOG.debug('attempting to connect to %25s', args.amqp_url)%0A    conn = pika.BlockingConnection(pika.URLParameters(args.amqp_url))%0A    chan = conn.channel()%0A    chan.basic_publish(exchange=args.exchange,%0A            routing_key=args.routing_key, body=message)%0A    print args.return_identifier%0A

add submit_job command to help testing