@resolveio/server-lib 12.4.4 → 12.4.6
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/managers/method.manager.js +38 -34
- package/managers/method.manager.js.map +1 -1
- package/managers/mongo.manager.js +96 -91
- package/managers/mongo.manager.js.map +1 -1
- package/managers/subscription.manager.js +101 -87
- package/managers/subscription.manager.js.map +1 -1
- package/package.json +1 -1
- package/server-app.js +1 -1
- package/server-app.js.map +1 -1
|
@@ -170,31 +170,37 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
170
170
|
_this._debugRemoveCacheHits = 0;
|
|
171
171
|
}, 60000);
|
|
172
172
|
setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
173
|
-
var
|
|
173
|
+
var _loop_1, this_1, i, queueArr, _loop_2, this_2, i;
|
|
174
174
|
var _this = this;
|
|
175
175
|
return __generator(this, function (_a) {
|
|
176
176
|
if (!this._runningQueue) {
|
|
177
177
|
this._runningQueue = true;
|
|
178
178
|
if (this._sendQueue.length) {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
179
|
+
_loop_1 = function (i) {
|
|
180
|
+
this_1._debugSendQueueHits += 1;
|
|
181
|
+
var ws = this_1._mainServer.getWS(this_1._sendQueue[i].id_ws);
|
|
182
|
+
if (ws && ws.readyState === ws.OPEN) {
|
|
183
|
+
if (ws.bufferedAmount < 20480) {
|
|
184
|
+
var sendItem = this_1._sendQueue.pop();
|
|
185
|
+
ws.send(JSON.stringify(sendItem.data), function (error) {
|
|
186
|
+
if (error) {
|
|
187
|
+
console.log('Error on WS: ', error);
|
|
188
|
+
if (_this.getEnableDebug()) {
|
|
189
|
+
console.log(new Date(), 'Sub Manager', 'Unsub WS', ws['user'], ws['id_socket'], 1);
|
|
190
|
+
}
|
|
191
|
+
_this.unsubscribeAll(ws);
|
|
190
192
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
});
|
|
193
|
+
});
|
|
194
|
+
}
|
|
194
195
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
196
|
+
else {
|
|
197
|
+
this_1._sendQueue.splice(i, 1);
|
|
198
|
+
}
|
|
199
|
+
};
|
|
200
|
+
this_1 = this;
|
|
201
|
+
// let startDate = new Date();
|
|
202
|
+
for (i = this._sendQueue.length - 1; i >= 0; i--) {
|
|
203
|
+
_loop_1(i);
|
|
198
204
|
}
|
|
199
205
|
// let endDate = new Date();
|
|
200
206
|
// this.currentPerfomanceMonitor.push({
|
|
@@ -210,63 +216,71 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
210
216
|
}
|
|
211
217
|
queueArr = this._mongoQueue.filter(function (a) { return !a.running; });
|
|
212
218
|
if (queueArr.length) {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
}
|
|
226
|
-
if (this._publications[mongoQueue_1.subscription.publication].user_specific) {
|
|
227
|
-
promises = [];
|
|
228
|
-
_loop_1 = function (j) {
|
|
229
|
-
var client = mongoQueue_1.subscription.clients[j];
|
|
230
|
-
var ws = this_1._mainServer.getWS(client.id_socket);
|
|
231
|
-
if (ws && ws['id_socket'] === client.id_socket) {
|
|
232
|
-
promises.push(this_1.sendDataToOne(ws, client.messageId, mongoQueue_1.subscription, mongoQueue_1.type, mongoQueue_1.collection).catch(function (err) {
|
|
233
|
-
_this._mainServer.getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + _this.serverConfig['CLIENT_NAME'], 'Error Detected During sendDataToOne - User Specific - Socket: ' + client.id_socket + ', User: ' + client.id_user + ', MessageId: ' + client.messageId + ', Pub: ' + mongoQueue_1.subscription.publication + ', Err: ' + JSON.stringify(err, null, 2));
|
|
234
|
-
return null;
|
|
235
|
-
}));
|
|
236
|
-
}
|
|
237
|
-
};
|
|
238
|
-
this_1 = this;
|
|
239
|
-
for (j = 0; j < mongoQueue_1.subscription.clients.length; j++) {
|
|
240
|
-
_loop_1(j);
|
|
219
|
+
queueArr.forEach(function (entry) {
|
|
220
|
+
entry.running = true;
|
|
221
|
+
});
|
|
222
|
+
_loop_2 = function (i) {
|
|
223
|
+
this_2._debugMongoQueueHits += 1;
|
|
224
|
+
var mongoQueue = queueArr[i];
|
|
225
|
+
if (!this_2._debugMongoQueueCollections.some(function (a) { return a.collection === mongoQueue.collection && a.publication === mongoQueue.subscription.publication; })) {
|
|
226
|
+
this_2._debugMongoQueueCollections.push({
|
|
227
|
+
collection: mongoQueue.collection,
|
|
228
|
+
publication: mongoQueue.subscription.publication,
|
|
229
|
+
hits: 1
|
|
230
|
+
});
|
|
241
231
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
232
|
+
else {
|
|
233
|
+
this_2._debugMongoQueueCollections.filter(function (a) { return a.collection === mongoQueue.collection && a.publication === mongoQueue.subscription.publication; })[0].hits += 1;
|
|
234
|
+
}
|
|
235
|
+
if (this_2._publications[mongoQueue.subscription.publication].user_specific) {
|
|
236
|
+
var promises = [];
|
|
237
|
+
var _loop_3 = function (j) {
|
|
238
|
+
var client = mongoQueue.subscription.clients[j];
|
|
239
|
+
var ws = this_2._mainServer.getWS(client.id_socket);
|
|
240
|
+
if (ws && ws['id_socket'] === client.id_socket) {
|
|
241
|
+
promises.push(this_2.sendDataToOne(ws, client.messageId, mongoQueue.subscription, mongoQueue.type, mongoQueue.collection).catch(function (err) {
|
|
242
|
+
_this._mainServer.getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + _this.serverConfig['CLIENT_NAME'], 'Error Detected During sendDataToOne - User Specific - Socket: ' + client.id_socket + ', User: ' + client.id_user + ', MessageId: ' + client.messageId + ', Pub: ' + mongoQueue.subscription.publication + ', Err: ' + JSON.stringify(err, null, 2));
|
|
243
|
+
return null;
|
|
244
|
+
}));
|
|
250
245
|
}
|
|
246
|
+
};
|
|
247
|
+
for (var j = 0; j < mongoQueue.subscription.clients.length; j++) {
|
|
248
|
+
_loop_3(j);
|
|
251
249
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
if (mongoQueue_1.run_again) {
|
|
257
|
-
mongoQueue_1.running = false;
|
|
258
|
-
mongoQueue_1.run_again = false;
|
|
259
|
-
}
|
|
260
|
-
else {
|
|
261
|
-
if (_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue_1._id) >= 0) {
|
|
262
|
-
_this._mongoQueue.splice(_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue_1._id), 1);
|
|
250
|
+
Promise.all(promises).then(function () {
|
|
251
|
+
if (mongoQueue.run_again) {
|
|
252
|
+
mongoQueue.running = false;
|
|
253
|
+
mongoQueue.run_again = false;
|
|
263
254
|
}
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
255
|
+
else {
|
|
256
|
+
if (_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue._id) >= 0) {
|
|
257
|
+
_this._mongoQueue.splice(_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue._id), 1);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
this_2.sendDataToAll(mongoQueue).then(function () {
|
|
264
|
+
if (mongoQueue.run_again) {
|
|
265
|
+
mongoQueue.running = false;
|
|
266
|
+
mongoQueue.run_again = false;
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
if (_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue._id) >= 0) {
|
|
270
|
+
_this._mongoQueue.splice(_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue._id), 1);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}, function () {
|
|
274
|
+
if (_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue._id) >= 0) {
|
|
275
|
+
_this._mongoQueue.splice(_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue._id), 1);
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
};
|
|
280
|
+
this_2 = this;
|
|
281
|
+
// let startDate = new Date();
|
|
282
|
+
for (i = queueArr.length - 1; i >= 0; i--) {
|
|
283
|
+
_loop_2(i);
|
|
270
284
|
}
|
|
271
285
|
// let endDate = new Date();
|
|
272
286
|
// this.currentPerfomanceMonitor.push({
|
|
@@ -284,9 +298,9 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
284
298
|
}
|
|
285
299
|
return [2 /*return*/];
|
|
286
300
|
});
|
|
287
|
-
}); },
|
|
301
|
+
}); }, 25);
|
|
288
302
|
setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
289
|
-
var _a, userCopy,
|
|
303
|
+
var _a, userCopy, _loop_4, this_3, i, i, sub, _loop_5, this_4, j;
|
|
290
304
|
return __generator(this, function (_b) {
|
|
291
305
|
switch (_b.label) {
|
|
292
306
|
case 0:
|
|
@@ -295,17 +309,17 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
295
309
|
case 1:
|
|
296
310
|
_a._loggedInUsers = _b.sent();
|
|
297
311
|
userCopy = common_1.deepCopy(this._loggedInUsers);
|
|
298
|
-
|
|
312
|
+
_loop_4 = function (i) {
|
|
299
313
|
var loggedInUser = userCopy[i];
|
|
300
314
|
if (!loggedInUser.date || Date.now() - loggedInUser.date.getTime() > 120000) {
|
|
301
|
-
if (
|
|
302
|
-
if (
|
|
303
|
-
console.log(new Date(), 'Sub Manager', 'Unsub WS',
|
|
315
|
+
if (this_3._mainServer.getWS(loggedInUser.id_ws)) {
|
|
316
|
+
if (this_3.getEnableDebug()) {
|
|
317
|
+
console.log(new Date(), 'Sub Manager', 'Unsub WS', this_3._mainServer.getWS(loggedInUser.id_ws)['user'], this_3._mainServer.getWS(loggedInUser.id_ws)['id_socket'], 2);
|
|
304
318
|
}
|
|
305
|
-
|
|
319
|
+
this_3.unsubscribeAll(this_3._mainServer.getWS(loggedInUser.id_ws));
|
|
306
320
|
}
|
|
307
321
|
else {
|
|
308
|
-
|
|
322
|
+
this_3._subscriptions.forEach(function (sub) {
|
|
309
323
|
for (var j = sub.clients.length - 1; j >= 0; j--) {
|
|
310
324
|
var client = sub.clients[j];
|
|
311
325
|
if (client.id_socket === loggedInUser.id_ws) {
|
|
@@ -314,27 +328,27 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
314
328
|
}
|
|
315
329
|
});
|
|
316
330
|
logged_in_users_collection_1.LoggedInUsers.deleteOne({ _id: loggedInUser._id });
|
|
317
|
-
if (
|
|
318
|
-
|
|
331
|
+
if (this_3._loggedInUsers.findIndex(function (a) { return a._id === loggedInUser._id; }) >= 0) {
|
|
332
|
+
this_3._loggedInUsers.splice(this_3._loggedInUsers.findIndex(function (a) { return a._id === loggedInUser._id; }), 1);
|
|
319
333
|
}
|
|
320
334
|
}
|
|
321
335
|
}
|
|
322
336
|
};
|
|
323
|
-
|
|
337
|
+
this_3 = this;
|
|
324
338
|
for (i = this._loggedInUsers.length - 1; i >= 0; i--) {
|
|
325
|
-
|
|
339
|
+
_loop_4(i);
|
|
326
340
|
}
|
|
327
341
|
for (i = 0; i < this._subscriptions.length; i++) {
|
|
328
342
|
sub = this._subscriptions[i];
|
|
329
|
-
|
|
343
|
+
_loop_5 = function (j) {
|
|
330
344
|
var client = sub.clients[j];
|
|
331
|
-
if (!
|
|
345
|
+
if (!this_4._loggedInUsers.some(function (a) { return a.id_ws === client.id_socket; })) {
|
|
332
346
|
sub.clients.splice(j, 1);
|
|
333
347
|
}
|
|
334
348
|
};
|
|
335
|
-
|
|
349
|
+
this_4 = this;
|
|
336
350
|
for (j = sub.clients.length - 1; j >= 0; j--) {
|
|
337
|
-
|
|
351
|
+
_loop_5(j);
|
|
338
352
|
}
|
|
339
353
|
}
|
|
340
354
|
return [2 /*return*/];
|