@tiledesk/tiledesk-server 2.18.4 → 2.18.16
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.
- package/CHANGELOG.md +27 -0
- package/app.js +2 -1
- package/event/kbEvent.js +12 -0
- package/event/webhookEvent.js +9 -0
- package/jobs.js +12 -1
- package/lib/analyticsClient.js +60 -0
- package/package.json +2 -2
- package/pubmodules/analytics-publisher/index.js +437 -0
- package/pubmodules/pubModulesManager.js +14 -0
- package/routes/answered.js +73 -0
- package/routes/kb.js +22 -2
- package/routes/project_user.js +51 -20
- package/routes/public-request.js +305 -239
- package/routes/request.js +11 -1
- package/routes/unanswered.js +71 -0
- package/routes/urlPreview.js +57 -0
- package/routes/webhook.js +2 -0
- package/services/Scheduler.js +13 -0
- package/services/aiManager.js +30 -0
- package/services/urlPreviewService.js +50 -0
- package/utils/jobs-worker-queue-manager/JobManagerV2.js +23 -12
- package/utils/jobs-worker-queue-manager/queueManagerClassV2.js +270 -270
- package/utils/transcriptTimezone.js +101 -0
- package/views/messages-layout.jade +130 -0
- package/views/messages.jade +23 -22
- package/views/messages_old.jade +11 -4
- package/.env.sample +0 -141
|
@@ -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
|
-
|
|
10
|
-
|
|
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
|
-
|
|
15
|
-
|
|
14
|
+
this.pubChannel = null;
|
|
15
|
+
this.offlinePubQueue = [];
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
// if the connection is closed or fails to be established at all, we will reconnect
|
|
18
|
+
this.amqpConn = null;
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
this.url = url || "amqp://localhost";
|
|
21
|
+
// process.env.CLOUDAMQP_URL + "?heartbeat=60"
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
// this.exchange = 'amq.topic';
|
|
24
|
+
this.exchange = 'tiledeskserver';
|
|
25
|
+
if (options && options.exchange != undefined) {
|
|
26
26
|
this.exchange = options.exchange;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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(
|
|
94
|
+
callback();
|
|
76
95
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
}
|
|
96
|
+
// return resolve();
|
|
97
|
+
// });
|
|
98
|
+
});
|
|
99
|
+
}
|
|
81
100
|
|
|
82
|
-
close(callback) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
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
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
-
|
|
119
|
-
|
|
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
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
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
|
-
|
|
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
|
-
|
|
237
|
+
processMsg2(msg) {
|
|
264
238
|
|
|
265
|
-
|
|
266
|
-
|
|
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
|
-
//
|
|
269
|
-
|
|
270
|
-
//
|
|
271
|
-
|
|
272
|
-
//
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
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
|
-
//
|
|
286
|
-
// console.log("
|
|
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
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
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
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
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
|
-
|
|
337
|
-
|
|
338
|
-
|
|
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
|
-
|
|
345
|
-
|
|
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
|
-
|
|
350
|
-
}
|
|
348
|
+
on(fn) {
|
|
349
|
+
listeners.push(fn);
|
|
350
|
+
}
|
|
351
351
|
|
|
352
352
|
|
|
353
353
|
|