1
1
# Common oxenmq object; this is used by workers and the oxenmq mule. We create, but do not start,
2
2
# this pre-forking.
3
3
4
- import oxenmq
5
- from oxenc import bt_serialize
4
+ import oxenmq , queue
5
+ from oxenc import bt_serialize , bt_deserialize
6
6
7
+ from mule import log_exceptions
7
8
from routes import omq_auth
8
9
from . import crypto , config
9
10
from .postfork import postfork
10
11
from .model .clientmanager import ClientManager
11
12
12
13
13
14
omq_global = None
15
+ global blueprints_global
16
+ blueprints_global = {}
14
17
15
18
16
19
class OMQ :
@@ -25,13 +28,16 @@ def __init__(self):
25
28
privkey = crypto ._privkey .encode (), pubkey = crypto .server_pubkey .encode ()
26
29
)
27
30
self ._omq .ephemeral_routing_id = True
28
-
31
+ self . client_map = {}
29
32
self .manager = ClientManager ()
30
33
self .test_suite = False
34
+ self .subreq_queue = queue .SimpleQueue ()
31
35
32
36
if uwsgi .mule_id () != 0 :
33
37
uwsgi .opt ['mule' ].setup_omq (self )
34
38
return
39
+
40
+ uwsgi .register_signal (123 , 'internal' , self .handle_proxied_omq_req )
35
41
36
42
from .web import app # Imported here to avoid circular import
37
43
@@ -46,15 +52,47 @@ def __init__(self):
46
52
global omq_global
47
53
omq_global = self
48
54
55
+
56
+ @log_exceptions
57
+ def subreq_response (self ):
58
+ pass
59
+
60
+
61
+ @log_exceptions
62
+ def handle_proxied_omq_req (self ):
63
+ id , subreq_body = self .send_mule (
64
+ command = 'get_next_request' ,
65
+ prefix = 'internal'
66
+ )
67
+
68
+ '''
69
+
70
+ Handle omq subrequest
71
+
72
+ '''
73
+
74
+ return
75
+
76
+ @log_exceptions
77
+ def get_next_request (self ):
78
+ subreq_body = self .subreq_queue .get ()
79
+ id = list (subreq_body .keys ())[0 ]
80
+ return id , subreq_body [id ]
81
+
49
82
50
- def register_client (self , cid , authlevel , bot : bool = False , priority : int = None ):
51
- self .manager .register_client (cid , authlevel , bot , priority )
52
- # TODO: add omq logic
83
+ @log_exceptions
84
+ def register_client (self , msg : oxenmq .Message ):
85
+ cid , authlevel , bot , priority = bt_deserialize (msg .data ()[0 ])
86
+ conn_id = msg .conn ()
87
+ self .client_map [conn_id ] = cid
88
+ self .manager .register_client (msg )
53
89
54
90
55
- def deregister_client (self , cid , bot : bool = False ):
56
- self .manager .register_client ()
57
- # TODO: add omq logic
91
+ @log_exceptions
92
+ def deregister_client (self , msg : oxenmq .Message ):
93
+ cid , bot = bt_deserialize (msg .data ()[0 ])
94
+ self .client_map .pop (cid )
95
+ self .manager .deregister_client (cid , bot )
58
96
59
97
60
98
def send_mule (self , command , * args , prefix = "worker." ):
0 commit comments