This repository was archived by the owner on Mar 14, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathautoexp_consumer.py
More file actions
executable file
·47 lines (40 loc) · 1.39 KB
/
autoexp_consumer.py
File metadata and controls
executable file
·47 lines (40 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python
import argparse
import autoexp
import json
import pika
import sys
import time
import logging
logging.basicConfig(level=logging.INFO)
parser = argparse.ArgumentParser(description='Run experiments from RabbitMQ server.')
parser.add_argument('--server', dest='server', action='store',
default='localhost',
help='address of the RabbitMQ server (default: localhost)')
args = parser.parse_args()
def all_done():
logging.info("Queue empty")
connection.close()
sys.exit(0)
connection = pika.BlockingConnection(pika.ConnectionParameters(
host=args.server))
channel = connection.channel()
channel.queue_declare(queue='autoexp_queue', durable=True)
logging.info('Getting messages.')
def callback(ch, method, properties, body):
try:
logging.debug("Received %r" % (body,))
input=json.loads(body)
autoexp.run_and_process(input, channel)
logging.debug("Done with %r" % (body,))
ch.basic_ack(delivery_tag = method.delivery_tag)
except:
print sys.exc_info()[0]
channel.basic_qos(prefetch_count=1)
while True:
method_frame, header_frame, body = channel.basic_get(queue = 'autoexp_queue')
#print method_frame, header_frame, body
if method_frame is not None and method_frame.NAME == 'Basic.GetOk':
callback(channel, method_frame, header_frame, body)
else:
all_done()