@tiledesk/tiledesk-server 2.18.5 → 2.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,49 +1,69 @@
1
1
  var amqp = require('amqplib/callback_api');
2
+ const winston = require('../../config/winston');
2
3
 
3
4
  var listeners = [];
4
5
 
5
-
6
6
  class QueueManager {
7
7
 
8
- constructor(url, options) {
9
- this.debug = false;
10
- if (options && options.debug!=undefined) {
8
+ constructor(url, options) {
9
+ this.debug = false;
10
+ if (options && options.debug != undefined) {
11
11
  this.debug = options.debug;
12
- }
12
+ }
13
13
 
14
- this.pubChannel = null;
15
- this.offlinePubQueue = [];
14
+ this.pubChannel = null;
15
+ this.offlinePubQueue = [];
16
16
 
17
- // if the connection is closed or fails to be established at all, we will reconnect
18
- this.amqpConn = null;
17
+ // if the connection is closed or fails to be established at all, we will reconnect
18
+ this.amqpConn = null;
19
19
 
20
- this.url = url || "amqp://localhost";
21
- // process.env.CLOUDAMQP_URL + "?heartbeat=60"
20
+ this.url = url || "amqp://localhost";
21
+ // process.env.CLOUDAMQP_URL + "?heartbeat=60"
22
22
 
23
- // this.exchange = 'amq.topic';
24
- this.exchange = 'tiledeskserver';
25
- if (options && options.exchange!=undefined) {
23
+ // this.exchange = 'amq.topic';
24
+ this.exchange = 'tiledeskserver';
25
+ if (options && options.exchange != undefined) {
26
26
  this.exchange = options.exchange;
27
- }
28
- this.defaultTopic = "subscription_run";
29
- if (options && options.defaultTopic!=undefined) {
30
- this.defaultTopic = options.defaultTopic;
31
- }
27
+ }
28
+ this.defaultTopic = "subscription_run";
29
+ if (options && options.defaultTopic != undefined) {
30
+ this.defaultTopic = options.defaultTopic;
31
+ }
32
+
33
+ this.topic = "jobsmanager";
34
+ if (options && options.topic != undefined) {
35
+ this.topic = options.topic;
36
+ }
37
+
38
+ this.deleteTopic = process.env.TRAIN_DELETE_QUEUE || "content_delete";
39
+ if (options && options.deleteTopic != undefined) {
40
+ this.deleteTopic = options.deleteTopic;
41
+ }
42
+
43
+ this.deleteRoutingKey = process.env.TRAIN_DELETE_ROUTING_KEY || this.deleteTopic;
44
+ if (options && options.deleteRoutingKey != undefined) {
45
+ this.deleteRoutingKey = options.deleteRoutingKey;
46
+ }
47
+
48
+ if (this.deleteTopic === this.topic) {
49
+ throw new Error("QueueManager: deleteTopic (TRAIN_DELETE_QUEUE) must differ from topic (main queue name)");
50
+ }
51
+
52
+ this.prefetch = 1;
53
+ if (process.env.TRAIN_PREFETCH) {
54
+ this.prefetch = Number(process.env.TRAIN_PREFETCH);
55
+ }
32
56
 
33
- this.topic = "jobsmanager";
34
- if (options && options.topic!=undefined) {
35
- this.topic = options.topic;
57
+ // this.listeners = [];
36
58
  }
37
59
 
38
- // this.listeners = [];
39
- }
40
60
 
61
+ connect(callback) {
62
+ var that = this;
63
+ // console.log("[JobWorker] connect", this.url);
64
+ // return new Promise(function (resolve, reject) {
65
+ amqp.connect(this.url, function (err, conn) {
41
66
 
42
- connect(callback) {
43
- var that = this;
44
- // console.log("[JobWorker] connect", this.url);
45
- // return new Promise(function (resolve, reject) {
46
- amqp.connect(this.url, function(err, conn) {
47
67
  if (err) {
48
68
  // if (this.debug) {console.log("[AMQP]", err.message);
49
69
  console.error("[JobWorker] AMQP error", err);
@@ -53,301 +73,281 @@ connect(callback) {
53
73
  }, 1000);
54
74
 
55
75
  }
56
- conn.on("error", function(err) {
76
+ conn.on("error", function (err) {
57
77
  if (err.message !== "Connection closing") {
58
78
  console.log("[JobWorker] AMQP conn error", err);
59
79
  }
60
80
  });
61
- conn.on("close", function() {
62
- // if (that.debug) {console.log("[JobWorker] AMQP reconnecting");}
63
- console.log("[JobWorker] AMQP reconnecting")
81
+ conn.on("close", function () {
82
+ if (that.debug) { console.log("[JobWorker] AMQP reconnecting"); }
64
83
  return setTimeout(() => {
65
84
  that.connect(callback);
66
85
  }, 1000);
67
86
  });
68
87
 
69
- console.log("[JobWorker] AMQP connected")
88
+ if (that.debug) { console.log("[JobWorker] AMQP connected"); }
70
89
  that.amqpConn = conn;
71
90
 
72
91
  // that.whenConnected(callback);
73
92
 
74
93
  if (callback) {
75
- callback('Connected', null);
94
+ callback();
76
95
  }
77
- // return resolve();
78
- // });
79
- });
80
- }
96
+ // return resolve();
97
+ // });
98
+ });
99
+ }
81
100
 
82
- close(callback) {
83
- if (this.debug) { console.log("Closing connection.."); };
84
- this.amqpConn.close((err) => {
85
- callback(err);
86
- });
101
+ close(callback) {
102
+ if (this.debug) { console.log("Closing connection.."); };
103
+ this.amqpConn.close((err) => {
104
+ callback(err);
105
+ });
87
106
 
88
- }
107
+ }
89
108
 
90
- whenConnected(callback) {
91
- var that = this;
92
- // that.startPublisher(callback);
93
- that.startPublisher();
94
- that.startWorker(callback);
95
- }
109
+ whenConnected(callback) {
110
+ var that = this;
111
+ // that.startPublisher(callback);
112
+ that.startPublisher();
113
+ that.startWorker(callback);
114
+ }
96
115
 
97
116
 
98
- startPublisher(callback) {
99
- var that = this;
100
- that.amqpConn.createConfirmChannel(function (err, ch) {
101
- if (that.closeOnErr(err)) return;
102
- ch.on("error", function (err) {
103
- if (that.debug) { console.log("[JobWorker] AMQP channel error", err); }
104
- });
105
- ch.on("close", function () {
106
- if (that.debug) { console.log("[JobWorker] AMQP channel closed"); }
107
- });
117
+ startPublisher(callback) {
118
+ var that = this;
119
+ that.amqpConn.createConfirmChannel(function (err, ch) {
120
+ if (that.closeOnErr(err)) return;
121
+ ch.on("error", function (err) {
122
+ if (that.debug) { console.log("[JobWorker] AMQP channel error", err); }
123
+ });
124
+ ch.on("close", function () {
125
+ if (that.debug) { console.log("[JobWorker] AMQP channel closed"); }
126
+ });
108
127
 
109
- // if (this.debug) {console.log("[AMQP] pubChannel");
110
- that.pubChannel = ch;
111
- // console.log("[JobWorker] that.pubChannel",that.pubChannel);
112
- // while (true) {
113
- // var m = that.offlinePubQueue.shift();
114
- // if (!m) break;
115
- // that.publish(m[0], m[1], m[2]);
116
- // }
128
+ // if (this.debug) {console.log("[AMQP] pubChannel");
129
+ that.pubChannel = ch;
130
+ // console.log("[JobWorker] that.pubChannel",that.pubChannel);
131
+ // while (true) {
132
+ // var m = that.offlinePubQueue.shift();
133
+ // if (!m) break;
134
+ // that.publish(m[0], m[1], m[2]);
135
+ // }
117
136
 
118
- if (callback) {
119
- callback(err);
120
- }
137
+ if (callback) {
138
+ callback(err);
139
+ }
121
140
 
122
- });
123
- }
141
+ });
142
+ }
124
143
 
125
- // method to publish a message, will queue messages internally if the connection is down and resend later
126
- publish(exchange, routingKey, content, callback) {
127
- var that = this;
128
- if (that.debug) {console.log("[JobWorker] that", that);}
129
- if (that.debug) {console.log("[JobWorker] that.pubChannel", that.pubChannel);}
130
- that.pubChannel.publish(exchange, routingKey, content, { persistent: false },
131
- function(err, ok) {
132
- callback(err, ok)
133
- }
134
- );
135
-
136
- // try {
137
- // if (that.debug) {console.log("[JobWorker] that", that);}
138
- // if (that.debug) {console.log("[JobWorker] that.pubChannel", that.pubChannel);}
139
- // that.pubChannel.publish(exchange, routingKey, content, { persistent: false },
140
- // function(err, ok) {
141
- // callback(err, ok)
142
- // // if (err) {
143
- // // // if (that.debug) {console.log("[JobWorker] AMQP publish", err);}
144
- // // // console.log("[JobWorker] AMQP publish", err);
145
- // // // that.offlinePubQueue.push([exchange, routingKey, content]);
146
- // // // that.pubChannel.connection.close();
147
- // // }
148
- // // console.log("publish OK")
149
- // // // if (that.debug) {console.log("[AMQP] publish sent", content);}
150
- // });
151
- // } catch (e) {
152
- // console.log("[JobWorker] AMQP publish catch", e);
153
- // if (this.debug) {console.log("[JobWorker] AMQP publish", e);}
154
- // that.offlinePubQueue.push([exchange, routingKey, content]);
155
- // }
156
- }
144
+ // method to publish a message, will queue messages internally if the connection is down and resend later
145
+ publish(exchange, routingKey, content, callback) {
146
+ var that = this;
147
+ if (that.debug) { console.log("[JobWorker] that", that); }
148
+ if (that.debug) { console.log("[JobWorker] that.pubChannel", that.pubChannel); }
149
+ that.pubChannel.publish(exchange, routingKey, content, { persistent: false },
150
+ function (err, ok) {
151
+ callback(err, ok)
152
+ }
153
+ );
154
+
155
+ // try {
156
+ // if (that.debug) {console.log("[JobWorker] that", that);}
157
+ // if (that.debug) {console.log("[JobWorker] that.pubChannel", that.pubChannel);}
158
+ // that.pubChannel.publish(exchange, routingKey, content, { persistent: false },
159
+ // function(err, ok) {
160
+ // callback(err, ok)
161
+ // // if (err) {
162
+ // // // if (that.debug) {console.log("[JobWorker] AMQP publish", err);}
163
+ // // // console.log("[JobWorker] AMQP publish", err);
164
+ // // // that.offlinePubQueue.push([exchange, routingKey, content]);
165
+ // // // that.pubChannel.connection.close();
166
+ // // }
167
+ // // console.log("publish OK")
168
+ // // // if (that.debug) {console.log("[AMQP] publish sent", content);}
169
+ // });
170
+ // } catch (e) {
171
+ // console.log("[JobWorker] AMQP publish catch", e);
172
+ // if (this.debug) {console.log("[JobWorker] AMQP publish", e);}
173
+ // that.offlinePubQueue.push([exchange, routingKey, content]);
174
+ // }
175
+ }
157
176
 
158
- // A worker that acks messages only if processed succesfully
159
- // var channel;
160
- startWorker(callback) {
161
- var that = this;
177
+ // A worker that acks messages only if processed succesfully
178
+ // var channel;
179
+ startWorker(callback) {
180
+ var that = this;
162
181
 
163
- that.amqpConn.createChannel(function(err, ch) {
182
+ that.amqpConn.createChannel(function (err, ch) {
164
183
  if (that.closeOnErr(err)) return;
165
- ch.on("error", function(err) {
166
- if (this.debug) {console.log("[JobWorker] AMQP channel error", err);}
184
+ ch.on("error", function (err) {
185
+ if (this.debug) { console.log("[JobWorker] AMQP channel error", err); }
167
186
  });
168
- ch.on("close", function() {
169
- if (this.debug) {console.log("[JobWorker] AMQP channel closed");}
187
+ ch.on("close", function () {
188
+ if (this.debug) { console.log("[JobWorker] AMQP channel closed"); }
170
189
  });
171
- ch.prefetch(10);
190
+ ch.prefetch(that.prefetch);
172
191
  ch.assertExchange(that.exchange, 'topic', {
173
- durable: false
192
+ //durable: false
193
+ durable: true
174
194
  });
175
195
 
176
- if (that.debug) {console.log("[JobWorker] AMQP that.topic", that.topic);}
177
- ch.assertQueue(that.topic, { durable: false }, function(err, _ok) {
196
+ if (that.debug) { console.log("[JobWorker] AMQP that.topic", that.topic); }
197
+ // ch.assertQueue(that.topic, { durable: false }, function (err, _ok) {
198
+ ch.assertQueue(that.topic, { durable: true }, function (err, _ok) {
178
199
  if (that.closeOnErr(err)) return;
179
- ch.bindQueue(_ok.queue, that.exchange, that.defaultTopic, {}, function(err3, oka) {
180
- if (that.debug) {console.log("[JobWorker] Queue bind: "+_ok.queue+ " err: "+err3+ " key: " + that.defaultTopic );}
181
- // if (this.debug) {console.log("Data queue", oka)
182
- });
183
- ch.bindQueue(_ok.queue, that.exchange, "functions", {}, function(err3, oka) {
184
- if (that.debug) {console.log("[JobWorker] Queue bind: "+_ok.queue+ " err: "+err3+ " key: " + "functions" );}
200
+ ch.bindQueue(_ok.queue, that.exchange, that.defaultTopic, {}, function (err3, oka) {
201
+ if (that.debug) { console.log("[JobWorker] Queue bind: " + _ok.queue + " err: " + err3 + " key: " + that.defaultTopic); }
185
202
  // if (this.debug) {console.log("Data queue", oka)
186
- });
187
-
188
- if (that.debug) {console.log("[JobWorker] AMQP that.topic", that.topic);}
189
- ch.consume(that.topic, that.processMsg2, { noAck: true });
190
- // ch.consume("jobs", that.processMsg, { noAck: false });
191
- if (that.debug) {console.log("[JobWorker] Worker is started");}
203
+ });
204
+ ch.bindQueue(_ok.queue, that.exchange, "functions", {}, function (err3, oka) {
205
+ if (that.debug) { console.log("[JobWorker] Queue bind: " + _ok.queue + " err: " + err3 + " key: " + "functions"); }
206
+ // if (this.debug) {console.log("Data queue", oka)
207
+ });
208
+
209
+ if (that.debug) { console.log("[JobWorker] AMQP that.topic", that.topic); }
210
+ ch.consume(_ok.queue, (msg) => {
211
+ that.processMsg3(msg, ch);
212
+ }, { noAck: false });
213
+
214
+ ch.assertQueue(that.deleteTopic, { durable: true }, function (errDel, delOk) {
215
+ if (that.closeOnErr(errDel)) return;
216
+ ch.bindQueue(delOk.queue, that.exchange, that.deleteRoutingKey, {}, function (err4) {
217
+ if (that.debug) { console.log("[JobWorker] Delete queue bind: " + delOk.queue + " err: " + err4 + " key: " + that.deleteRoutingKey); }
218
+ });
219
+ ch.consume(delOk.queue, (msg) => {
220
+ that.processDeleteMsg(msg, ch);
221
+ }, { noAck: false });
222
+ if (that.debug) { console.log("[JobWorker] Delete worker is started on queue " + delOk.queue); }
223
+ });
224
+
225
+ if (that.debug) { console.log("[JobWorker] Worker is started"); }
192
226
 
193
227
  if (callback) {
194
228
  callback();
195
- if (that.debug) {console.log("[JobWorker] called callback worker");}
229
+ if (that.debug) { console.log("[JobWorker] called callback worker"); }
196
230
  }
197
231
  });
198
-
199
-
200
- });
201
- }
202
-
203
-
204
-
205
- // work(msg, cb) {
206
- // const message_string = msg.content.toString();
207
- // const topic = msg.fields.routingKey //.replace(/[.]/g, '/');
208
-
209
- // if (this.debug) {console.log("Got msg topic:" + topic);
210
-
211
- // if (this.debug) {console.log("Got msg:"+ message_string + " topic:" + topic);
212
-
213
- // if (topic === 'subscription_run') {
214
- // if (this.debug) {console.log("here topic:" + topic);
215
- // // requestEvent.emit('request.create.queue', msg.content);
216
- // subscriptionEvent.emit('subscription.run.queue', JSON.parse(message_string));
217
- // }
218
- // cb(true);
219
- // if (this.debug) {console.log("okookokkkkkkk msg:");
220
- // }
221
-
222
- processMsg2(msg) {
223
-
224
- // console.log("processMsg2:", msg);
225
-
226
- const message_string = msg.content.toString();
227
- // console.log("processMsg2.1:", msg);
228
-
229
- const topic = msg.fields.routingKey //.replace(/[.]/g, '/');
230
- // console.log("processMsg2.2:", msg);
231
-
232
- // if (this.debug) {console.log("Got msg topic:" + topic);} //this is undefined in this method
233
- // console.log("Got msg topic:" + topic);
234
-
235
- // if (this.debug) {console.log("Got msg1:"+ message_string + " topic:" + topic);}
236
- // console.log("Got msg1:"+ message_string + " topic:" + topic);
237
-
238
- if (topic === 'functions') {
239
- // if (this.debug) {console.log("Got msg2:"+ JSON.stringify(message_string) + " topic:" + topic);}
240
- // console.log("Got msg2:"+ JSON.stringify(message_string) + " topic:" + topic);
241
232
 
242
- var fdata = JSON.parse(message_string)
243
233
 
244
- // if (this.debug) {console.log("Got msg3:"+ fdata.function + " fdata.function:", fdata.payload);}
245
-
246
-
247
-
248
- /*
249
-
250
- // var fields = Object.keys(fdata.payload).map((key) => [key, fdata.payload[key]]);
251
-
252
- // var fields = Object.keys(fdata.payload)
253
-
254
- // if (this.debug) {console.log("Got fields:"+ fields );
255
-
256
- // eval(fdata.function)
257
-
258
- */
259
-
260
- if (fdata.function) {
261
- var fn = new Function("payload", fdata.function);
234
+ });
235
+ }
262
236
 
263
- // if (this.debug) {console.log("Got fn:"+ fn);}
237
+ processMsg2(msg) {
264
238
 
265
- /*
266
- // var fn = new Function(fields, fdata.function);
239
+ // console.log("processMsg2:", msg);
240
+
241
+ const message_string = msg.content.toString();
242
+ // console.log("processMsg2.1:", msg);
243
+
244
+ const topic = msg.fields.routingKey //.replace(/[.]/g, '/');
245
+ // console.log("processMsg2.2:", msg);
246
+
247
+ // if (this.debug) {console.log("Got msg topic:" + topic);} //this is undefined in this method
248
+ // console.log("Got msg topic:" + topic);
249
+
250
+ // if (this.debug) {console.log("Got msg1:"+ message_string + " topic:" + topic);}
251
+ // console.log("Got msg1:"+ message_string + " topic:" + topic);
252
+
253
+ if (topic === 'functions') {
254
+ // if (this.debug) {console.log("Got msg2:"+ JSON.stringify(message_string) + " topic:" + topic);}
255
+ // console.log("Got msg2:"+ JSON.stringify(message_string) + " topic:" + topic);
256
+
257
+ var fdata = JSON.parse(message_string)
258
+
259
+ // if (this.debug) {console.log("Got msg3:"+ fdata.function + " fdata.function:", fdata.payload);}
260
+
261
+
262
+
263
+ /*
264
+
265
+ // var fields = Object.keys(fdata.payload).map((key) => [key, fdata.payload[key]]);
267
266
 
268
- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/Function
269
- // var fn = new Function("name",'if (this.debug) {console.log("ciao: " + name);');
270
- // fn("andrea")
271
-
272
- // var dataArray = Object.keys(fdata.payload).map(function(k){return fdata.payload[k]});
273
- // if (this.debug) {console.log("Got dataArray:", dataArray );
274
-
275
- // fn(dataArray);
276
- */
277
-
278
-
279
- var ret = fn(fdata.payload)
280
- // if (this.debug) {console.log("Got ret:"+ ret);}
281
- // console.log("Got ret:"+ ret);
282
-
267
+ // var fields = Object.keys(fdata.payload)
268
+
269
+ // if (this.debug) {console.log("Got fields:"+ fields );
270
+
271
+ // eval(fdata.function)
272
+
273
+ */
274
+
275
+ if (fdata.function) {
276
+ var fn = new Function("payload", fdata.function);
277
+
278
+ // if (this.debug) {console.log("Got fn:"+ fn);}
279
+
280
+ /*
281
+ // var fn = new Function(fields, fdata.function);
282
+
283
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/Function
284
+ // var fn = new Function("name",'if (this.debug) {console.log("ciao: " + name);');
285
+ // fn("andrea")
286
+
287
+ // var dataArray = Object.keys(fdata.payload).map(function(k){return fdata.payload[k]});
288
+ // if (this.debug) {console.log("Got dataArray:", dataArray );
289
+
290
+ // fn(dataArray);
291
+ */
292
+
293
+
294
+ var ret = fn(fdata.payload)
295
+ // if (this.debug) {console.log("Got ret:"+ ret);}
296
+ // console.log("Got ret:"+ ret);
297
+
298
+ }
299
+
300
+ // else {
301
+ // console.log("no function found");
302
+ // }
303
+
304
+
283
305
  }
284
-
285
- // else {
286
- // console.log("no function found");
287
- // }
306
+
307
+ // if (topic === 'subscription_run') {
308
+ // if (this.debug) {console.log("here topic:" + topic);
309
+ // // requestEvent.emit('request.create.queue', msg.content);
310
+ // subscriptionEvent.emit('subscription.run.queue', JSON.parse(message_string));
311
+ // }
288
312
 
289
-
290
- }
291
-
292
- // if (topic === 'subscription_run') {
293
- // if (this.debug) {console.log("here topic:" + topic);
294
- // // requestEvent.emit('request.create.queue', msg.content);
295
- // subscriptionEvent.emit('subscription.run.queue', JSON.parse(message_string));
296
- // }
297
313
 
298
-
299
- // serve?
300
- // if (this.debug) {console.log("listeners.length:" + listeners.length);}
301
-
302
- if (listeners && listeners.length>0) {
303
- for( var i = 0; i< listeners.length; i++) {
304
- // if (this.debug) {console.log("listeners[i]:" + listeners[i]);}
305
- listeners[i](fdata);
314
+ // serve?
315
+ // if (this.debug) {console.log("listeners.length:" + listeners.length);}
316
+
317
+ if (listeners && listeners.length>0) {
318
+ for( var i = 0; i< listeners.length; i++) {
319
+ // if (this.debug) {console.log("listeners[i]:" + listeners[i]);}
320
+ listeners[i](fdata);
321
+ }
306
322
  }
323
+
324
+ // if (this.debug) {console.log("listeners", this.listeners);
307
325
  }
308
326
 
309
- // if (this.debug) {console.log("listeners", this.listeners);
310
- }
311
- // processMsg(msg) {
312
- // if (this.debug) {console.log("processMsg msg:", msg);
313
-
314
- // var that = this;
315
- // that.work(msg, function(ok) {
316
- // try {
317
- // if (ok)
318
- // ch.ack(msg);
319
- // else
320
- // ch.reject(msg, true);
321
- // } catch (e) {
322
- // that.closeOnErr(e);
323
- // }
324
- // });
325
- // }
326
-
327
- closeOnErr(err) {
328
- if (!err) return false;
329
- console.error("[JobWorker] AMQP error", err);
330
- this.amqpConn.close();
331
- return true;
332
- }
327
+ closeOnErr(err) {
328
+ if (!err) return false;
329
+ console.error("[JobWorker] AMQP error", err);
330
+ this.amqpConn.close();
331
+ return true;
332
+ }
333
333
 
334
- sendJson(data, topic, callback) {
334
+ sendJson(data, topic, callback) {
335
335
 
336
- this.publish(this.exchange, topic || this.defaultTopic, Buffer.from(JSON.stringify(data)), (err, ok) => {
337
- if (callback) {
338
- callback(err, ok);
339
- }
340
- });
341
- }
336
+ this.publish(this.exchange, topic || this.defaultTopic, Buffer.from(JSON.stringify(data)), (err, ok) => {
337
+ if (callback) {
338
+ callback(err, ok);
339
+ }
340
+ });
341
+ }
342
342
 
343
- send(string, topic) {
344
- if (this.debug) {console.log("[JobWorker] send(string): ", string);}
345
- this.publish(this.exchange, topic || this.defaultTopic, Buffer.from(string));
346
- }
343
+ send(string, topic) {
344
+ if (this.debug) { console.log("[JobWorker] send(string): ", string); }
345
+ this.publish(this.exchange, topic || this.defaultTopic, Buffer.from(string));
346
+ }
347
347
 
348
- on(fn) {
349
- listeners.push(fn);
350
- }
348
+ on(fn) {
349
+ listeners.push(fn);
350
+ }
351
351
 
352
352
 
353
353