-
Notifications
You must be signed in to change notification settings - Fork 0
/
sendtasks.py
executable file
·42 lines (38 loc) · 1.36 KB
/
sendtasks.py
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
#!/usr/bin/env python
# coding: utf-8
import sys
import argparse
import zmq
DEFAULT_STATION_HOST = "localhost"
DEFAULT_STATION_PORT = 5556
DEFAULT_TASKS_FILE = "tasks.json"
def main(rfile, host, port):
context = zmq.Context()
socket = context.socket(zmq.REQ)
socket.connect("tcp://%s:%s" % (host, port))
tasks = open("tasks.json")
sys.stdout.write("Connecting to Station and sending requests... ")
sys.stdout.flush()
socket.send(tasks.read())
try:
reply = socket.recv_string()
except KeyboardInterrupt:
return
sys.stdout.write("DONE\n")
print ("Station replied: %s" % reply)
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("--file", help="request JSON file"
" (default: %s)" % DEFAULT_TASKS_FILE,
type=str, default=DEFAULT_TASKS_FILE)
parser.add_argument("--host", help="station host"
" (default: %s)" % DEFAULT_STATION_HOST,
type=str, default=DEFAULT_STATION_HOST)
parser.add_argument("--port", help="station port"
" (default: %s)" % DEFAULT_STATION_PORT,
type=int, default=DEFAULT_STATION_PORT)
args = parser.parse_args()
try:
main(args.file, args.host, args.port)
except KeyboardInterrupt:
sys.exit(0)