2011-04-01 23:34:33 -07:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import sys
|
2011-05-24 12:45:08 -07:00
|
|
|
import time
|
2011-04-01 23:34:33 -07:00
|
|
|
import interp.bootstrap
|
|
|
|
from interp.cluster import QueueManager, get_qs
|
2011-05-26 09:12:01 -07:00
|
|
|
from optparse import OptionParser
|
2011-04-01 23:34:33 -07:00
|
|
|
|
2011-05-26 09:12:01 -07:00
|
|
|
if __name__ == '__main__':
|
|
|
|
parser = OptionParser(usage = "usage: %s [options] <status|watch|add|fresult #|slay|clear|clearall|clearresults>")
|
2011-04-01 23:34:33 -07:00
|
|
|
|
2011-05-26 09:12:01 -07:00
|
|
|
parser.add_option('-p', '--port',
|
|
|
|
type="int", dest="port", default=6666,
|
|
|
|
help="specify the port to use on the server (default: %default)")
|
2011-04-01 23:34:33 -07:00
|
|
|
|
2011-05-26 09:12:01 -07:00
|
|
|
parser.add_option('-a', '--auth-key',
|
|
|
|
type="str", dest="authkey", default='asdf',
|
|
|
|
help="authkey (default: %default)")
|
2011-04-01 23:34:33 -07:00
|
|
|
|
2011-05-26 09:12:01 -07:00
|
|
|
(options, args) = parser.parse_args()
|
2011-04-01 23:34:33 -07:00
|
|
|
|
2011-05-26 09:12:01 -07:00
|
|
|
if len(args) == 0:
|
|
|
|
cmd = 'status'
|
2011-05-24 12:45:08 -07:00
|
|
|
else:
|
2011-05-26 09:12:01 -07:00
|
|
|
cmd = args[0]
|
|
|
|
|
|
|
|
m = QueueManager(address=('', options.port), authkey=options.authkey)
|
|
|
|
m.connect()
|
|
|
|
|
|
|
|
tq,rq,mq,sq = get_qs(m)
|
|
|
|
|
|
|
|
if cmd.startswith("st"):
|
|
|
|
print "interp queue status:"
|
|
|
|
print " tasksq : %d" % tq.qsize()
|
|
|
|
print " resultsq : %d" % rq.qsize()
|
|
|
|
print " masterq : %d" % mq.qsize()
|
|
|
|
print " minionsq : %d" % sq.qsize()
|
|
|
|
|
|
|
|
if cmd.startswith("wa"):
|
|
|
|
if len(args) == 2:
|
|
|
|
sleeptime = float(args[1])
|
|
|
|
else:
|
|
|
|
sleeptime = 1
|
|
|
|
|
|
|
|
i = 0
|
|
|
|
while True:
|
|
|
|
time.sleep(sleeptime)
|
|
|
|
if i % 20 == 0:
|
|
|
|
print "tasksq resultsq masterq minionsq"
|
|
|
|
print "%d %d %d %d" % \
|
|
|
|
(tq.qsize(),
|
|
|
|
rq.qsize(),
|
|
|
|
mq.qsize(),
|
|
|
|
sq.qsize(),)
|
|
|
|
i += 1
|
|
|
|
|
|
|
|
if cmd == 'add':
|
|
|
|
for i in xrange(int(args[1])):
|
|
|
|
mq.put('jane%d' % i)
|
|
|
|
|
|
|
|
if cmd == 'fresult':
|
|
|
|
for i in xrange(int(args[1])):
|
|
|
|
rq.put('fake.%d' % i)
|
|
|
|
|
|
|
|
if cmd == 'slay':
|
|
|
|
if len(args) == 1:
|
|
|
|
for i in xrange(mq.qsize()):
|
|
|
|
print i, "killing", mq.get()
|
|
|
|
sq.put("slay")
|
|
|
|
elif len(args) == 2:
|
|
|
|
for i in xrange(int(args[1])):
|
|
|
|
print i, "killing", mq.get()
|
|
|
|
sq.put("slay")
|
|
|
|
|
|
|
|
|
|
|
|
if cmd == 'clear':
|
|
|
|
for i in xrange(tq.qsize()): print tq.get()
|
|
|
|
for i in xrange(rq.qsize()): print rq.get()
|
|
|
|
|
|
|
|
if cmd == 'clearall':
|
|
|
|
for i in xrange(tq.qsize()): print tq.get()
|
|
|
|
for i in xrange(rq.qsize()): print rq.get()
|
|
|
|
for i in xrange(mq.qsize()): print mq.get()
|
|
|
|
for i in xrange(sq.qsize()): print sq.get()
|
|
|
|
|
|
|
|
if cmd == 'clearresults':
|
|
|
|
for i in xrange(rq.qsize()): print rq.get()
|