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_download_output.py
More file actions
48 lines (40 loc) · 1.41 KB
/
autoexp_download_output.py
File metadata and controls
48 lines (40 loc) · 1.41 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
48
#!/usr/bin/env python
import argparse
import autoexp
import csv
import json
import pika
import sys
import logging
logging.basicConfig(level=logging.INFO)
parser = argparse.ArgumentParser(description='Download results 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()
connection = pika.BlockingConnection(pika.ConnectionParameters(
host=args.server))
channel = connection.channel()
channel.queue_declare(queue='autoexp_output_queue', durable=True)
writer = csv.DictWriter(sys.stdout, fieldnames=autoexp.ids + autoexp.measured)
writer.writeheader()
def all_done():
logging.info("Finished")
connection.close()
sys.exit(0)
def callback(ch, method, properties, body):
try:
logging.debug("Received %r" % (body,))
output=json.loads(body)
writer.writerow(output)
logging.debug("Done with %r" % (output,))
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_output_queue')
if method_frame is not None and method_frame.NAME == 'Basic.GetOk':
callback(channel, method_frame, header_frame, body)
else:
all_done()