-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmqks_eval
executable file
·62 lines (45 loc) · 1.65 KB
/
mqks_eval
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python
"""
Usage:
./mqks_eval 'state.worker' # Prints "0".
./mqks_eval '--worker=1 len(state.queues)' # Prints number of queues at w1.
./mqks_eval 'get_module("mqks.server.lib.workers").get_worker("q1")' # Any module is available, even not imported yet.
./mqks_eval 'get_worker("q1")' # See shortcuts in "mqks/server/actions/_eval.py".
./mqks_eval '--client [mqks.delete_queue(q, confirm=True) for q in "aa bb cc".split(" ")]' # Direct connections from client to required workers.
See spells in "stats.py".
"""
### import
import gevent, gevent.monkey
gevent.monkey.patch_all()
import os, sys
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
from mqks.client import mqks
from mqks.server.config import config as server_config
### config
TIMEOUT = 5
RAISE_TIMEOUT = False
### main
def main():
mqks.config['workers'] = server_config['workers']
mqks.connect()
data = sys.argv[1]
### client
if data.startswith('--client'):
_, code = data.split(' ', 1)
print(eval(code))
return
### server
if data.startswith('--worker='):
worker, code = data.split(' ', 1)
_, worker = worker.split('=', 1)
worker = int(worker)
else:
worker = 0
code = data
try:
print(mqks._eval(code, worker=worker, timeout=TIMEOUT))
except gevent.Timeout:
if RAISE_TIMEOUT:
raise
if __name__ == '__main__':
main()