|
8 | 8 |
|
9 | 9 | from config import Config |
10 | 10 |
|
11 | | -class WorkerChannel(Channel): |
12 | | - """Channel for communication with a worker. Pass the id of the worker to communicate with an |
13 | | - existing worker. |
14 | | - """ |
15 | | - @classmethod |
16 | | - def get_name(cls, worker_id): |
17 | | - """Return the name of the channel that would be used for this worker_id.""" |
18 | | - return 'worker_{}'.format(worker_id) |
19 | | - |
20 | | - def __init__(self, worker_id=None): |
21 | | - self.uri = Config.get('rabbit', 'uri') |
22 | | - ch_name = None |
23 | | - if worker_id: |
24 | | - ch_name = WorkerChannel.get_name(worker_id) |
25 | | - super().__init__(name=ch_name, |
26 | | - connection_type=RabbitConnection, |
27 | | - uri=self.uri) |
28 | | - |
29 | | - |
30 | | -class SpawnerWorkerChannel(Channel): |
31 | | - """Channel facilitating communication between a spawner and a worker during startup. Pass the name of the worker to communicate with an |
32 | | - existing worker. |
33 | | - """ |
34 | | - def __init__(self, worker_id=None): |
35 | | - self.uri = Config.get('rabbit', 'uri') |
36 | | - ch_name = None |
37 | | - if worker_id: |
38 | | - ch_name = 'spawner_worker_{}'.format(worker_id) |
39 | | - super().__init__(name=ch_name, |
40 | | - connection_type=RabbitConnection, |
41 | | - uri=self.uri) |
| 11 | +# class WorkerChannel(Channel): |
| 12 | +# """Channel for communication with a worker. Pass the id of the worker to communicate with an |
| 13 | +# existing worker. |
| 14 | +# """ |
| 15 | +# @classmethod |
| 16 | +# def get_name(cls, worker_id): |
| 17 | +# """Return the name of the channel that would be used for this worker_id.""" |
| 18 | +# return 'worker_{}'.format(worker_id) |
| 19 | +# |
| 20 | +# def __init__(self, worker_id=None): |
| 21 | +# self.uri = Config.get('rabbit', 'uri') |
| 22 | +# ch_name = None |
| 23 | +# if worker_id: |
| 24 | +# ch_name = WorkerChannel.get_name(worker_id) |
| 25 | +# super().__init__(name=ch_name, |
| 26 | +# connection_type=RabbitConnection, |
| 27 | +# uri=self.uri) |
| 28 | + |
| 29 | + |
| 30 | +# class SpawnerWorkerChannel(Channel): |
| 31 | +# """Channel facilitating communication between a spawner and a worker during startup. Pass the name of the worker to communicate with an |
| 32 | +# existing worker. |
| 33 | +# """ |
| 34 | +# def __init__(self, worker_id=None): |
| 35 | +# self.uri = Config.get('rabbit', 'uri') |
| 36 | +# ch_name = None |
| 37 | +# if worker_id: |
| 38 | +# ch_name = 'spawner_worker_{}'.format(worker_id) |
| 39 | +# super().__init__(name=ch_name, |
| 40 | +# connection_type=RabbitConnection, |
| 41 | +# uri=self.uri) |
42 | 42 |
|
43 | 43 |
|
44 | 44 | class ClientsChannel(Channel): |
@@ -70,50 +70,51 @@ def request_delete_client(self, tenant, actor_id, worker_id, client_id, secret): |
70 | 70 | return self.put_sync(msg, timeout=60) |
71 | 71 |
|
72 | 72 |
|
73 | | -class CommandChannel(Channel): |
74 | | - """Work with commands on the command channel.""" |
75 | | - |
76 | | - def __init__(self, name='default'): |
77 | | - self.uri = Config.get('rabbit', 'uri') |
78 | | - queues_list = Config.get('spawner', 'host_queues').replace(' ', '') |
79 | | - valid_queues = queues_list.split(',') |
80 | | - if name not in valid_queues: |
81 | | - raise Exception('Invalid Queue name.') |
82 | | - |
83 | | - |
84 | | - super().__init__(name='command_channel_{}'.format(name), |
85 | | - connection_type=RabbitConnection, |
86 | | - uri=self.uri) |
87 | | - |
88 | | - def put_cmd(self, actor_id, worker_id, image, tenant, stop_existing=True): |
89 | | - """Put a new command on the command channel.""" |
90 | | - msg = {'actor_id': actor_id, |
91 | | - 'worker_id': worker_id, |
92 | | - 'image': image, |
93 | | - 'tenant': tenant, |
94 | | - 'stop_existing': stop_existing} |
95 | | - |
96 | | - self.put(msg) |
97 | | - |
98 | | - |
99 | | -class EventsChannel(Channel): |
100 | | - """Work with events on the events channel.""" |
101 | | - |
102 | | - event_queue_names = ('default', |
103 | | - ) |
104 | | - |
105 | | - def __init__(self, name='default'): |
106 | | - self.uri = Config.get('rabbit', 'uri') |
107 | | - if name not in EventsChannel.event_queue_names: |
108 | | - raise Exception('Invalid Events Channel Queue name.') |
109 | | - |
110 | | - super().__init__(name='events_channel_{}'.format(name), |
111 | | - connection_type=RabbitConnection, |
112 | | - uri=self.uri) |
113 | | - |
114 | | - def put_event(self, json_data): |
115 | | - """Put a new event on the events channel.""" |
116 | | - self.put(json_data) |
| 73 | +# class CommandChannel(Channel): |
| 74 | +# """Work with commands on the command channel.""" |
| 75 | +# |
| 76 | +# def __init__(self, name='default'): |
| 77 | +# self.uri = Config.get('rabbit', 'uri') |
| 78 | +# queues_list = Config.get('spawner', 'host_queues').replace(' ', '') |
| 79 | +# valid_queues = queues_list.split(',') |
| 80 | +# if name not in valid_queues: |
| 81 | +# raise Exception('Invalid Queue name.') |
| 82 | +# |
| 83 | +# |
| 84 | +# super().__init__(name='command_channel_{}'.format(name), |
| 85 | +# connection_type=RabbitConnection, |
| 86 | +# uri=self.uri) |
| 87 | +# |
| 88 | +# def put_cmd(self, actor_id, worker_id, image, revision, tenant, stop_existing=True): |
| 89 | +# """Put a new command on the command channel.""" |
| 90 | +# msg = {'actor_id': actor_id, |
| 91 | +# 'worker_id': worker_id, |
| 92 | +# 'image': image, |
| 93 | +# 'revision': revision, |
| 94 | +# 'tenant': tenant, |
| 95 | +# 'stop_existing': stop_existing} |
| 96 | +# |
| 97 | +# self.put(msg) |
| 98 | + |
| 99 | + |
| 100 | +# class EventsChannel(Channel): |
| 101 | +# """Work with events on the events channel.""" |
| 102 | +# |
| 103 | +# event_queue_names = ('default', |
| 104 | +# ) |
| 105 | +# |
| 106 | +# def __init__(self, name='default'): |
| 107 | +# self.uri = Config.get('rabbit', 'uri') |
| 108 | +# if name not in EventsChannel.event_queue_names: |
| 109 | +# raise Exception('Invalid Events Channel Queue name.') |
| 110 | +# |
| 111 | +# super().__init__(name='events_channel_{}'.format(name), |
| 112 | +# connection_type=RabbitConnection, |
| 113 | +# uri=self.uri) |
| 114 | +# |
| 115 | +# def put_event(self, json_data): |
| 116 | +# """Put a new event on the events channel.""" |
| 117 | +# self.put(json_data) |
117 | 118 |
|
118 | 119 |
|
119 | 120 | class BinaryChannel(BasicChannel): |
@@ -154,31 +155,83 @@ def get_one(self): |
154 | 155 | from queues import BinaryTaskQueue |
155 | 156 |
|
156 | 157 |
|
157 | | -class ActorMsgChannel(BinaryTaskQueue): |
158 | | - def __init__(self, actor_id): |
159 | | - super().__init__(name='actor_msg_{}'.format(actor_id)) |
| 158 | +class EventsChannel(BinaryTaskQueue): |
| 159 | + """Work with events on the events channel.""" |
160 | 160 |
|
161 | | - def put_msg(self, message, d={}, **kwargs): |
162 | | - d['message'] = message |
163 | | - for k, v in kwargs: |
164 | | - d[k] = v |
165 | | - self.put(d) |
| 161 | + event_queue_names = ('default', |
| 162 | + ) |
| 163 | + |
| 164 | + def __init__(self, name='default'): |
| 165 | + self.uri = Config.get('rabbit', 'uri') |
| 166 | + if name not in EventsChannel.event_queue_names: |
| 167 | + raise Exception('Invalid Events Channel Queue name.') |
| 168 | + |
| 169 | + super().__init__(name='events_channel_{}'.format(name)) |
| 170 | + |
| 171 | + def put_event(self, json_data): |
| 172 | + """Put a new event on the events channel.""" |
| 173 | + self.put(json_data) |
166 | 174 |
|
167 | 175 |
|
168 | | -class ActorMSSgChannel(BinaryChannel): |
169 | | - """Work with messages sent to a specific actor. |
| 176 | +class CommandChannel(BinaryTaskQueue): |
| 177 | + """Work with commands on the command channel.""" |
| 178 | + |
| 179 | + def __init__(self, name='default'): |
| 180 | + self.uri = Config.get('rabbit', 'uri') |
| 181 | + queues_list = Config.get('spawner', 'host_queues').replace(' ', '') |
| 182 | + valid_queues = queues_list.split(',') |
| 183 | + if name not in valid_queues: |
| 184 | + raise Exception('Invalid Queue name.') |
| 185 | + |
| 186 | + |
| 187 | + super().__init__(name='command_channel_{}'.format(name)) |
| 188 | + |
| 189 | + def put_cmd(self, actor_id, worker_id, image, revision, tenant, stop_existing=True): |
| 190 | + """Put a new command on the command channel.""" |
| 191 | + msg = {'actor_id': actor_id, |
| 192 | + 'worker_id': worker_id, |
| 193 | + 'image': image, |
| 194 | + 'revision': revision, |
| 195 | + 'tenant': tenant, |
| 196 | + 'stop_existing': stop_existing} |
| 197 | + |
| 198 | + self.put(msg) |
| 199 | + |
| 200 | + |
| 201 | +class SpawnerWorkerChannel(BinaryTaskQueue): |
| 202 | + """Channel facilitating communication between a spawner and a worker during startup. Pass the name of the worker to communicate with an |
| 203 | + existing worker. |
170 | 204 | """ |
171 | | - def __init__(self, actor_id): |
| 205 | + def __init__(self, worker_id=None): |
172 | 206 | self.uri = Config.get('rabbit', 'uri') |
173 | | - super().__init__(name='actor_msg_{}'.format(actor_id), |
174 | | - connection_type=RabbitConnection, |
175 | | - uri=self.uri) |
| 207 | + ch_name = None |
| 208 | + if worker_id: |
| 209 | + ch_name = 'spawner_worker_{}'.format(worker_id) |
| 210 | + super().__init__(name=ch_name) |
| 211 | + |
| 212 | + |
| 213 | +class WorkerChannel(BinaryTaskQueue): |
| 214 | + """Channel for communication with a worker. Pass the id of the worker to communicate with an |
| 215 | + existing worker. |
| 216 | + """ |
| 217 | + @classmethod |
| 218 | + def get_name(cls, worker_id): |
| 219 | + """Return the name of the channel that would be used for this worker_id.""" |
| 220 | + return 'worker_{}'.format(worker_id) |
| 221 | + |
| 222 | + def __init__(self, worker_id=None): |
| 223 | + self.uri = Config.get('rabbit', 'uri') |
| 224 | + ch_name = None |
| 225 | + if worker_id: |
| 226 | + ch_name = WorkerChannel.get_name(worker_id) |
| 227 | + super().__init__(name=ch_name) |
| 228 | + |
| 229 | + |
| 230 | +class ActorMsgChannel(BinaryTaskQueue): |
| 231 | + def __init__(self, actor_id): |
| 232 | + super().__init__(name='actor_msg_{}'.format(actor_id)) |
176 | 233 |
|
177 | 234 | def put_msg(self, message, d={}, **kwargs): |
178 | | - """Pass a message to an actor's inbox, thereby invoking it. `message` is the request |
179 | | - body msg parameter; `d` is a dictionary built from the request query parameters; |
180 | | - additional metadata (e.g. jwt, username) can be passed through kwargs. |
181 | | - """ |
182 | 235 | d['message'] = message |
183 | 236 | for k, v in kwargs: |
184 | 237 | d[k] = v |
|
0 commit comments