@resolveio/server-lib 20.14.25 → 20.14.26
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/subscription.manager.js +4 -35
- package/managers/subscription.manager.js.map +1 -1
- package/managers/worker-dispatcher.manager.js +0 -84
- package/managers/worker-dispatcher.manager.js.map +1 -1
- package/managers/worker-server.manager.js +1 -19
- package/managers/worker-server.manager.js.map +1 -1
- package/package.json +1 -1
- package/server-app.d.ts +0 -5
- package/server-app.js +82 -195
- package/server-app.js.map +1 -1
package/server-app.js
CHANGED
|
@@ -79,7 +79,6 @@ var http_1 = require("http");
|
|
|
79
79
|
var jwt = require("jsonwebtoken");
|
|
80
80
|
var moment = require("moment-timezone");
|
|
81
81
|
var msgpackr_1 = require("msgpackr");
|
|
82
|
-
var perf_hooks_1 = require("perf_hooks");
|
|
83
82
|
var url_1 = require("url");
|
|
84
83
|
var WebSocket = require("ws");
|
|
85
84
|
var log_collection_1 = require("./collections/log.collection");
|
|
@@ -119,10 +118,6 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
119
118
|
this._clientHeartbeatIntervalMs = 20000;
|
|
120
119
|
this._clientHeartbeatInitialDelayMs = 5000;
|
|
121
120
|
this._clientHeartbeatBackpressureBytes = 5 * 1024 * 1024;
|
|
122
|
-
this._eventLoopLagIntervalMs = 500;
|
|
123
|
-
this._eventLoopLagThresholdMs = 300;
|
|
124
|
-
this._eventLoopDelayStatsIntervalMs = 10000;
|
|
125
|
-
this._slowHandlerThresholdMs = 200;
|
|
126
121
|
}
|
|
127
122
|
ResolveIOMainServer.create = function () {
|
|
128
123
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -164,7 +159,6 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
164
159
|
_this._debugMsgQueue = 0;
|
|
165
160
|
_this._debugMsgRecv = 0;
|
|
166
161
|
}, 60000);
|
|
167
|
-
this.startEventLoopLagMonitor();
|
|
168
162
|
process.removeAllListeners('unhandledRejection');
|
|
169
163
|
process.on('unhandledRejection', function (error, rej) { return __awaiter(_this, void 0, void 0, function () {
|
|
170
164
|
var _a, normalizedError, correlationId, errorDetails, diffTimeSec;
|
|
@@ -386,76 +380,6 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
386
380
|
});
|
|
387
381
|
});
|
|
388
382
|
};
|
|
389
|
-
ResolveIOMainServer.prototype.startEventLoopLagMonitor = function () {
|
|
390
|
-
var _this = this;
|
|
391
|
-
var lastTick = Date.now();
|
|
392
|
-
var delayMonitor = (0, perf_hooks_1.monitorEventLoopDelay)({ resolution: 20 });
|
|
393
|
-
delayMonitor.enable();
|
|
394
|
-
var gcKindLabels = {};
|
|
395
|
-
var perfConstants = perf_hooks_1.performance === null || perf_hooks_1.performance === void 0 ? void 0 : perf_hooks_1.performance.constants;
|
|
396
|
-
if (perfConstants) {
|
|
397
|
-
if (typeof perfConstants.NODE_PERFORMANCE_GC_MAJOR !== 'undefined') {
|
|
398
|
-
gcKindLabels[perfConstants.NODE_PERFORMANCE_GC_MAJOR] = 'major';
|
|
399
|
-
}
|
|
400
|
-
if (typeof perfConstants.NODE_PERFORMANCE_GC_MINOR !== 'undefined') {
|
|
401
|
-
gcKindLabels[perfConstants.NODE_PERFORMANCE_GC_MINOR] = 'minor';
|
|
402
|
-
}
|
|
403
|
-
if (typeof perfConstants.NODE_PERFORMANCE_GC_INCREMENTAL !== 'undefined') {
|
|
404
|
-
gcKindLabels[perfConstants.NODE_PERFORMANCE_GC_INCREMENTAL] = 'incremental';
|
|
405
|
-
}
|
|
406
|
-
if (typeof perfConstants.NODE_PERFORMANCE_GC_WEAKCB !== 'undefined') {
|
|
407
|
-
gcKindLabels[perfConstants.NODE_PERFORMANCE_GC_WEAKCB] = 'weakcb';
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
var gcObserver = new perf_hooks_1.PerformanceObserver(function (list) {
|
|
411
|
-
var e_1, _a;
|
|
412
|
-
try {
|
|
413
|
-
for (var _b = __values(list.getEntries()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
414
|
-
var entry = _c.value;
|
|
415
|
-
var kindLabel = gcKindLabels[entry.kind] || entry.kind;
|
|
416
|
-
console.log(new Date(), '[GC]', {
|
|
417
|
-
kind: kindLabel,
|
|
418
|
-
durationMs: (0, common_1.round)(entry.duration)
|
|
419
|
-
});
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
423
|
-
finally {
|
|
424
|
-
try {
|
|
425
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
426
|
-
}
|
|
427
|
-
finally { if (e_1) throw e_1.error; }
|
|
428
|
-
}
|
|
429
|
-
});
|
|
430
|
-
gcObserver.observe({ entryTypes: ['gc'] });
|
|
431
|
-
setInterval(function () {
|
|
432
|
-
var now = Date.now();
|
|
433
|
-
var lagMs = now - lastTick - _this._eventLoopLagIntervalMs;
|
|
434
|
-
lastTick = now;
|
|
435
|
-
if (lagMs >= _this._eventLoopLagThresholdMs) {
|
|
436
|
-
var mem = process.memoryUsage();
|
|
437
|
-
console.log(new Date(), '[Event Loop Lag]', {
|
|
438
|
-
lagMs: (0, common_1.round)(lagMs),
|
|
439
|
-
rssMB: (0, common_1.round)(mem.rss / (1024 * 1024)),
|
|
440
|
-
heapUsedMB: (0, common_1.round)(mem.heapUsed / (1024 * 1024)),
|
|
441
|
-
heapTotalMB: (0, common_1.round)(mem.heapTotal / (1024 * 1024))
|
|
442
|
-
});
|
|
443
|
-
}
|
|
444
|
-
}, this._eventLoopLagIntervalMs);
|
|
445
|
-
setInterval(function () {
|
|
446
|
-
var p99Ms = (0, common_1.round)(delayMonitor.percentile(99) / 1e6);
|
|
447
|
-
var maxMs = (0, common_1.round)(delayMonitor.max / 1e6);
|
|
448
|
-
var meanMs = (0, common_1.round)(delayMonitor.mean / 1e6);
|
|
449
|
-
if (p99Ms >= _this._eventLoopLagThresholdMs || maxMs >= _this._eventLoopLagThresholdMs) {
|
|
450
|
-
console.log(new Date(), '[Event Loop Delay Stats]', {
|
|
451
|
-
p99Ms: p99Ms,
|
|
452
|
-
maxMs: maxMs,
|
|
453
|
-
meanMs: meanMs
|
|
454
|
-
});
|
|
455
|
-
}
|
|
456
|
-
delayMonitor.reset();
|
|
457
|
-
}, this._eventLoopDelayStatsIntervalMs);
|
|
458
|
-
};
|
|
459
383
|
ResolveIOMainServer.prototype.shutdownNetworkServers = function () {
|
|
460
384
|
return __awaiter(this, void 0, void 0, function () {
|
|
461
385
|
return __generator(this, function (_a) {
|
|
@@ -988,7 +912,7 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
988
912
|
}
|
|
989
913
|
});
|
|
990
914
|
ws.on('message', function (message) { return __awaiter(_this, void 0, void 0, function () {
|
|
991
|
-
var socketData, usedBinary, bufferPayload, decodeResult, decodeResult, decodeResult, view, decodeResult,
|
|
915
|
+
var socketData, usedBinary, bufferPayload, decodeResult, decodeResult, decodeResult, view, decodeResult, e_1, correlationId, context;
|
|
992
916
|
return __generator(this, function (_a) {
|
|
993
917
|
switch (_a.label) {
|
|
994
918
|
case 0:
|
|
@@ -1036,15 +960,15 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
1036
960
|
}
|
|
1037
961
|
return [3 /*break*/, 4];
|
|
1038
962
|
case 2:
|
|
1039
|
-
|
|
1040
|
-
console.log('Error - WS message parse',
|
|
963
|
+
e_1 = _a.sent();
|
|
964
|
+
console.log('Error - WS message parse', e_1);
|
|
1041
965
|
correlationId = (0, common_1.objectIdHexString)();
|
|
1042
966
|
context = {
|
|
1043
967
|
rawBinary: bufferPayload ? bufferPayload.toString('base64') : undefined,
|
|
1044
968
|
rawMessage: typeof message === 'string' ? message : undefined,
|
|
1045
|
-
error:
|
|
969
|
+
error: e_1 instanceof Error ? { name: e_1.name, message: e_1.message, stack: e_1.stack } : e_1
|
|
1046
970
|
};
|
|
1047
|
-
return [4 /*yield*/, this.reportServerError('SERVER - JSON Parse Error - ' + resolveio_server_app_1.ResolveIOServer.getServerConfig()['CLIENT_NAME'], correlationId, context, { context: 'websocket-message-parse' }, 'error',
|
|
971
|
+
return [4 /*yield*/, this.reportServerError('SERVER - JSON Parse Error - ' + resolveio_server_app_1.ResolveIOServer.getServerConfig()['CLIENT_NAME'], correlationId, context, { context: 'websocket-message-parse' }, 'error', e_1 instanceof Error ? e_1.stack : undefined)];
|
|
1048
972
|
case 3:
|
|
1049
973
|
_a.sent();
|
|
1050
974
|
return [2 /*return*/];
|
|
@@ -1084,8 +1008,8 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
1084
1008
|
}); });
|
|
1085
1009
|
// Keep alive timer
|
|
1086
1010
|
setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1087
|
-
var _a, _b, ws,
|
|
1088
|
-
var
|
|
1011
|
+
var _a, _b, ws, e_2_1;
|
|
1012
|
+
var e_2, _c;
|
|
1089
1013
|
return __generator(this, function (_d) {
|
|
1090
1014
|
switch (_d.label) {
|
|
1091
1015
|
case 0:
|
|
@@ -1126,14 +1050,14 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
1126
1050
|
return [3 /*break*/, 1];
|
|
1127
1051
|
case 9: return [3 /*break*/, 12];
|
|
1128
1052
|
case 10:
|
|
1129
|
-
|
|
1130
|
-
|
|
1053
|
+
e_2_1 = _d.sent();
|
|
1054
|
+
e_2 = { error: e_2_1 };
|
|
1131
1055
|
return [3 /*break*/, 12];
|
|
1132
1056
|
case 11:
|
|
1133
1057
|
try {
|
|
1134
1058
|
if (_b && !_b.done && (_c = _a.return)) _c.call(_a);
|
|
1135
1059
|
}
|
|
1136
|
-
finally { if (
|
|
1060
|
+
finally { if (e_2) throw e_2.error; }
|
|
1137
1061
|
return [7 /*endfinally*/];
|
|
1138
1062
|
case 12: return [2 /*return*/];
|
|
1139
1063
|
}
|
|
@@ -1142,8 +1066,8 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
1142
1066
|
};
|
|
1143
1067
|
ResolveIOMainServer.prototype.processSocketMessage = function (ws, socketData) {
|
|
1144
1068
|
return __awaiter(this, void 0, void 0, function () {
|
|
1145
|
-
var socketData_1, socketData_1_1, message,
|
|
1146
|
-
var
|
|
1069
|
+
var socketData_1, socketData_1_1, message, e_3_1;
|
|
1070
|
+
var e_3, _a;
|
|
1147
1071
|
return __generator(this, function (_b) {
|
|
1148
1072
|
switch (_b.label) {
|
|
1149
1073
|
case 0:
|
|
@@ -1182,14 +1106,14 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
1182
1106
|
return [3 /*break*/, 2];
|
|
1183
1107
|
case 5: return [3 /*break*/, 8];
|
|
1184
1108
|
case 6:
|
|
1185
|
-
|
|
1186
|
-
|
|
1109
|
+
e_3_1 = _b.sent();
|
|
1110
|
+
e_3 = { error: e_3_1 };
|
|
1187
1111
|
return [3 /*break*/, 8];
|
|
1188
1112
|
case 7:
|
|
1189
1113
|
try {
|
|
1190
1114
|
if (socketData_1_1 && !socketData_1_1.done && (_a = socketData_1.return)) _a.call(socketData_1);
|
|
1191
1115
|
}
|
|
1192
|
-
finally { if (
|
|
1116
|
+
finally { if (e_3) throw e_3.error; }
|
|
1193
1117
|
return [7 /*endfinally*/];
|
|
1194
1118
|
case 8: return [2 /*return*/];
|
|
1195
1119
|
}
|
|
@@ -1300,43 +1224,33 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
1300
1224
|
};
|
|
1301
1225
|
ResolveIOMainServer.prototype.handleClientMessage = function (ws, msg) {
|
|
1302
1226
|
return __awaiter(this, void 0, void 0, function () {
|
|
1303
|
-
var
|
|
1227
|
+
var messageRoute_1, messageDate, messageId, type, subType, pub, serverRes, offlineUpdates, i, update, data, updateRoute, updateDate, updateMessageId, updateType, method, serverResMethod, err_2, dataCopy, date, msgId, msgType, methodName, ack, method, forceWorker, targetWorkerIndex, hasWorkerForMethod, isExcludedFromWorker, errorRes, shouldDispatchToWorker, errorRes, err_3;
|
|
1304
1228
|
var _a;
|
|
1305
1229
|
return __generator(this, function (_b) {
|
|
1306
1230
|
switch (_b.label) {
|
|
1307
1231
|
case 0:
|
|
1308
|
-
|
|
1309
|
-
logRoute = msg && msg[0];
|
|
1310
|
-
logType = null;
|
|
1311
|
-
logDetail = null;
|
|
1312
|
-
_b.label = 1;
|
|
1313
|
-
case 1:
|
|
1314
|
-
_b.trys.push([1, , 25, 26]);
|
|
1232
|
+
_b.trys.push([0, 24, , 25]);
|
|
1315
1233
|
messageRoute_1 = msg[0];
|
|
1316
1234
|
messageDate = msg[1];
|
|
1317
1235
|
messageId = msg[2];
|
|
1318
1236
|
type = msg[3];
|
|
1319
|
-
logRoute = messageRoute_1;
|
|
1320
|
-
logType = type;
|
|
1321
1237
|
if (!this.publicProgram && this._clientRoutes.some(function (a) { return messageRoute_1.includes(a); }) && !ws['doc_user'].roles.groups.some(function (a) { return a.views.some(function (b) { return messageRoute_1.includes(b) || b.includes(messageRoute_1); }); }) && !ws['doc_user'].roles.super_admin) {
|
|
1322
1238
|
return [2 /*return*/];
|
|
1323
1239
|
}
|
|
1324
|
-
if (!(type === 'subscription')) return [3 /*break*/,
|
|
1240
|
+
if (!(type === 'subscription')) return [3 /*break*/, 4];
|
|
1325
1241
|
subType = msg[4];
|
|
1326
1242
|
pub = msg[5];
|
|
1327
|
-
|
|
1328
|
-
if (!(subType === 'sub')) return [3 /*break*/, 3];
|
|
1243
|
+
if (!(subType === 'sub')) return [3 /*break*/, 2];
|
|
1329
1244
|
return [4 /*yield*/, this._subscriptionManager.subscribe(messageRoute_1, messageDate, ws, messageId, pub, msg.slice(6))];
|
|
1330
|
-
case
|
|
1245
|
+
case 1:
|
|
1331
1246
|
_b.sent();
|
|
1332
|
-
return [3 /*break*/,
|
|
1333
|
-
case
|
|
1247
|
+
return [3 /*break*/, 3];
|
|
1248
|
+
case 2:
|
|
1334
1249
|
this._subscriptionManager.unsubscribe(messageRoute_1, messageDate, ws, messageId, pub, msg.slice(6));
|
|
1335
|
-
_b.label =
|
|
1336
|
-
case
|
|
1337
|
-
case
|
|
1338
|
-
if (!(!this.publicProgram && type === 'offline')) return [3 /*break*/,
|
|
1339
|
-
logDetail = 'offline';
|
|
1250
|
+
_b.label = 3;
|
|
1251
|
+
case 3: return [3 /*break*/, 23];
|
|
1252
|
+
case 4:
|
|
1253
|
+
if (!(!this.publicProgram && type === 'offline')) return [3 /*break*/, 16];
|
|
1340
1254
|
serverRes = {
|
|
1341
1255
|
messageId: messageId,
|
|
1342
1256
|
hasError: false,
|
|
@@ -1347,11 +1261,10 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
1347
1261
|
}
|
|
1348
1262
|
this._offlineUpdates.push(ws);
|
|
1349
1263
|
offlineUpdates = msg[4];
|
|
1350
|
-
logDetail = "offline:".concat(Array.isArray(offlineUpdates) ? offlineUpdates.length : 0);
|
|
1351
1264
|
i = 0;
|
|
1352
|
-
_b.label =
|
|
1353
|
-
case
|
|
1354
|
-
if (!(i < offlineUpdates.length)) return [3 /*break*/,
|
|
1265
|
+
_b.label = 5;
|
|
1266
|
+
case 5:
|
|
1267
|
+
if (!(i < offlineUpdates.length)) return [3 /*break*/, 15];
|
|
1355
1268
|
update = offlineUpdates[i];
|
|
1356
1269
|
data = update.data;
|
|
1357
1270
|
updateRoute = data.shift();
|
|
@@ -1368,11 +1281,11 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
1368
1281
|
this._websocketManager.send(ws, serverResMethod);
|
|
1369
1282
|
}
|
|
1370
1283
|
if (method === 'insertDocument' && data[0] === 'driver-gps') {
|
|
1371
|
-
return [3 /*break*/,
|
|
1284
|
+
return [3 /*break*/, 14];
|
|
1372
1285
|
}
|
|
1373
|
-
if (!(method !== 'reportBuilderGetResults' && method !== 'reportBuilderGetDistinctValue' && method !== 'reportBuilderBuildTree' && method !== 'generatePDF' && method !== 'getWOOfflineData' && method !== 'countQuery' && method !== 'countWithQuery' && method !== 'countCollectionWithQuery' && method !== 'find' && method !== 'findOne' && method !== 'findWithOptions' && method !== 'getDrivers' && method !== 'processAirdropDistribution' && method !== 'qbHandleResponse')) return [3 /*break*/,
|
|
1286
|
+
if (!(method !== 'reportBuilderGetResults' && method !== 'reportBuilderGetDistinctValue' && method !== 'reportBuilderBuildTree' && method !== 'generatePDF' && method !== 'getWOOfflineData' && method !== 'countQuery' && method !== 'countWithQuery' && method !== 'countCollectionWithQuery' && method !== 'find' && method !== 'findOne' && method !== 'findWithOptions' && method !== 'getDrivers' && method !== 'processAirdropDistribution' && method !== 'qbHandleResponse')) return [3 /*break*/, 8];
|
|
1374
1287
|
if (!(resolveio_server_app_1.ResolveIOServer.getServerConfig()['ROOT_URL'] !== 'https://resolveio.com'
|
|
1375
|
-
&& resolveio_server_app_1.ResolveIOServer.getServerConfig()['ROOT_URL'] !== 'http://localhost:4200')) return [3 /*break*/,
|
|
1288
|
+
&& resolveio_server_app_1.ResolveIOServer.getServerConfig()['ROOT_URL'] !== 'http://localhost:4200')) return [3 /*break*/, 6];
|
|
1376
1289
|
resolveio_server_app_1.ResolveIOServer.getLocalLogManager().writeLog({
|
|
1377
1290
|
type: 'log',
|
|
1378
1291
|
data: {
|
|
@@ -1390,8 +1303,8 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
1390
1303
|
instance_index: process.env.NODE_APP_INSTANCE || '0'
|
|
1391
1304
|
}
|
|
1392
1305
|
});
|
|
1393
|
-
return [3 /*break*/,
|
|
1394
|
-
case
|
|
1306
|
+
return [3 /*break*/, 8];
|
|
1307
|
+
case 6: return [4 /*yield*/, log_collection_1.Logs.insertOne({
|
|
1395
1308
|
_id: (0, common_1.objectIdHexString)(),
|
|
1396
1309
|
type: 'client-request',
|
|
1397
1310
|
collection: '',
|
|
@@ -1406,51 +1319,50 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
1406
1319
|
instance: 'backend.resolveio.com',
|
|
1407
1320
|
instance_index: process.env.NODE_APP_INSTANCE || '0'
|
|
1408
1321
|
})];
|
|
1409
|
-
case
|
|
1322
|
+
case 7:
|
|
1410
1323
|
_b.sent();
|
|
1324
|
+
_b.label = 8;
|
|
1325
|
+
case 8:
|
|
1326
|
+
if (!this._methodManager._methods[method]) return [3 /*break*/, 13];
|
|
1411
1327
|
_b.label = 9;
|
|
1412
1328
|
case 9:
|
|
1413
|
-
|
|
1414
|
-
_b.label = 10;
|
|
1415
|
-
case 10:
|
|
1416
|
-
_b.trys.push([10, 12, , 13]);
|
|
1329
|
+
_b.trys.push([9, 11, , 12]);
|
|
1417
1330
|
return [4 /*yield*/, (_a = this._methodManager.callMethod).call.apply(_a, __spreadArray([Object.assign({}, this._methodManager, method_manager_1.MethodManager.prototype, { id_user: ws['id_user'], user: ws['user'], id_ws: ws['id_socket'] }), method], __read(data), false))];
|
|
1418
|
-
case
|
|
1331
|
+
case 10:
|
|
1419
1332
|
_b.sent();
|
|
1420
|
-
return [3 /*break*/,
|
|
1421
|
-
case
|
|
1333
|
+
return [3 /*break*/, 12];
|
|
1334
|
+
case 11:
|
|
1422
1335
|
err_2 = _b.sent();
|
|
1423
1336
|
console.log(new Date(), 'Offline Error', JSON.stringify(err_2, null, 2));
|
|
1424
|
-
return [3 /*break*/,
|
|
1425
|
-
case
|
|
1337
|
+
return [3 /*break*/, 12];
|
|
1338
|
+
case 12:
|
|
1426
1339
|
if (method === 'updateDocumentOffline' || method === 'updateDocumentPropsOffline') {
|
|
1427
1340
|
resolveio_server_app_1.ResolveIOServer.getMongoManager().invalidateQueryCache(data[0]);
|
|
1428
1341
|
}
|
|
1429
|
-
return [3 /*break*/,
|
|
1430
|
-
case
|
|
1342
|
+
return [3 /*break*/, 14];
|
|
1343
|
+
case 13:
|
|
1431
1344
|
console.log('Offline - Could not find method: ' + method);
|
|
1432
|
-
_b.label =
|
|
1433
|
-
case
|
|
1345
|
+
_b.label = 14;
|
|
1346
|
+
case 14:
|
|
1434
1347
|
i++;
|
|
1435
|
-
return [3 /*break*/,
|
|
1436
|
-
case
|
|
1348
|
+
return [3 /*break*/, 5];
|
|
1349
|
+
case 15:
|
|
1437
1350
|
this._offlineUpdates.splice(this._offlineUpdates.map(function (a) { return a['id_socket']; }).indexOf(ws['id_socket']), 1);
|
|
1438
|
-
return [3 /*break*/,
|
|
1439
|
-
case
|
|
1351
|
+
return [3 /*break*/, 23];
|
|
1352
|
+
case 16:
|
|
1440
1353
|
dataCopy = __spreadArray([], __read(msg), false);
|
|
1441
|
-
|
|
1354
|
+
dataCopy.shift();
|
|
1442
1355
|
date = dataCopy.shift();
|
|
1443
1356
|
msgId = dataCopy.shift();
|
|
1444
1357
|
msgType = dataCopy.shift();
|
|
1445
|
-
if (!(msgType === 'method')) return [3 /*break*/,
|
|
1358
|
+
if (!(msgType === 'method')) return [3 /*break*/, 23];
|
|
1446
1359
|
methodName = dataCopy.shift();
|
|
1447
|
-
logDetail = "method:".concat(methodName);
|
|
1448
1360
|
if (ws['user_readonly']) {
|
|
1449
1361
|
return [2 /*return*/];
|
|
1450
1362
|
}
|
|
1451
|
-
if (!(methodName !== 'reportBuilderGetResults' && methodName !== 'reportBuilderGetDistinctValue' && methodName !== 'reportBuilderBuildTree' && methodName !== 'generatePDF' && methodName !== 'getWOOfflineData' && methodName !== 'countQuery' && methodName !== 'countWithQuery' && methodName !== 'countCollectionWithQuery' && methodName !== 'find' && methodName !== 'findOne' && methodName !== 'findWithOptions' && methodName !== 'getDrivers' && methodName !== 'processAirdropDistribution')) return [3 /*break*/,
|
|
1363
|
+
if (!(methodName !== 'reportBuilderGetResults' && methodName !== 'reportBuilderGetDistinctValue' && methodName !== 'reportBuilderBuildTree' && methodName !== 'generatePDF' && methodName !== 'getWOOfflineData' && methodName !== 'countQuery' && methodName !== 'countWithQuery' && methodName !== 'countCollectionWithQuery' && methodName !== 'find' && methodName !== 'findOne' && methodName !== 'findWithOptions' && methodName !== 'getDrivers' && methodName !== 'processAirdropDistribution')) return [3 /*break*/, 19];
|
|
1452
1364
|
if (!(resolveio_server_app_1.ResolveIOServer.getServerConfig()['ROOT_URL'] !== 'https://resolveio.com'
|
|
1453
|
-
&& resolveio_server_app_1.ResolveIOServer.getServerConfig()['ROOT_URL'] !== 'http://localhost:4200')) return [3 /*break*/,
|
|
1365
|
+
&& resolveio_server_app_1.ResolveIOServer.getServerConfig()['ROOT_URL'] !== 'http://localhost:4200')) return [3 /*break*/, 17];
|
|
1454
1366
|
resolveio_server_app_1.ResolveIOServer.getLocalLogManager().writeLog({
|
|
1455
1367
|
type: 'log',
|
|
1456
1368
|
data: {
|
|
@@ -1468,8 +1380,8 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
1468
1380
|
instance_index: process.env.NODE_APP_INSTANCE || '0'
|
|
1469
1381
|
}
|
|
1470
1382
|
});
|
|
1471
|
-
return [3 /*break*/,
|
|
1472
|
-
case
|
|
1383
|
+
return [3 /*break*/, 19];
|
|
1384
|
+
case 17: return [4 /*yield*/, log_collection_1.Logs.insertOne({
|
|
1473
1385
|
_id: (0, common_1.objectIdHexString)(),
|
|
1474
1386
|
type: 'client-request',
|
|
1475
1387
|
collection: '',
|
|
@@ -1484,10 +1396,10 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
1484
1396
|
instance: 'backend.resolveio.com',
|
|
1485
1397
|
instance_index: process.env.NODE_APP_INSTANCE || '0'
|
|
1486
1398
|
})];
|
|
1487
|
-
case
|
|
1399
|
+
case 18:
|
|
1488
1400
|
_b.sent();
|
|
1489
|
-
_b.label =
|
|
1490
|
-
case
|
|
1401
|
+
_b.label = 19;
|
|
1402
|
+
case 19:
|
|
1491
1403
|
ack = {
|
|
1492
1404
|
messageId: msgId,
|
|
1493
1405
|
hasError: false,
|
|
@@ -1534,15 +1446,15 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
1534
1446
|
this._workerDispatcherManager &&
|
|
1535
1447
|
(hasWorkerForMethod || forceWorker) &&
|
|
1536
1448
|
(forceWorker || !isExcludedFromWorker));
|
|
1537
|
-
if (!shouldDispatchToWorker) return [3 /*break*/,
|
|
1449
|
+
if (!shouldDispatchToWorker) return [3 /*break*/, 20];
|
|
1538
1450
|
this._workerDispatcherManager.sendClientTask(msgId, methodName, dataCopy, {
|
|
1539
1451
|
id_user: ws['id_user'],
|
|
1540
1452
|
user: ws['user'],
|
|
1541
1453
|
id_ws: ws['id_socket']
|
|
1542
1454
|
});
|
|
1543
|
-
return [3 /*break*/,
|
|
1544
|
-
case
|
|
1545
|
-
if (!(forceWorker && this._isWorkersEnabled)) return [3 /*break*/,
|
|
1455
|
+
return [3 /*break*/, 23];
|
|
1456
|
+
case 20:
|
|
1457
|
+
if (!(forceWorker && this._isWorkersEnabled)) return [3 /*break*/, 21];
|
|
1546
1458
|
errorRes = {
|
|
1547
1459
|
messageId: msgId,
|
|
1548
1460
|
hasError: true,
|
|
@@ -1551,30 +1463,19 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
1551
1463
|
if (ws && ws.readyState === ws.OPEN) {
|
|
1552
1464
|
this._websocketManager.send(ws, errorRes);
|
|
1553
1465
|
}
|
|
1554
|
-
return [3 /*break*/,
|
|
1555
|
-
case
|
|
1466
|
+
return [3 /*break*/, 23];
|
|
1467
|
+
case 21:
|
|
1556
1468
|
// No worker available: do method locally
|
|
1557
|
-
return [4 /*yield*/, this.callMethodLocally(ws, msgId, methodName, dataCopy
|
|
1558
|
-
case
|
|
1469
|
+
return [4 /*yield*/, this.callMethodLocally(ws, msgId, methodName, dataCopy)];
|
|
1470
|
+
case 22:
|
|
1559
1471
|
// No worker available: do method locally
|
|
1560
1472
|
_b.sent();
|
|
1561
|
-
_b.label =
|
|
1562
|
-
case
|
|
1563
|
-
case
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
durationMs: durationMs,
|
|
1568
|
-
route: logRoute,
|
|
1569
|
-
type: logType,
|
|
1570
|
-
detail: logDetail,
|
|
1571
|
-
id_user: ws['id_user'] || null,
|
|
1572
|
-
user: ws['user'] || null,
|
|
1573
|
-
id_ws: ws['id_socket'] || null
|
|
1574
|
-
});
|
|
1575
|
-
}
|
|
1576
|
-
return [7 /*endfinally*/];
|
|
1577
|
-
case 26: return [2 /*return*/];
|
|
1473
|
+
_b.label = 23;
|
|
1474
|
+
case 23: return [3 /*break*/, 25];
|
|
1475
|
+
case 24:
|
|
1476
|
+
err_3 = _b.sent();
|
|
1477
|
+
throw err_3;
|
|
1478
|
+
case 25: return [2 /*return*/];
|
|
1578
1479
|
}
|
|
1579
1480
|
});
|
|
1580
1481
|
});
|
|
@@ -1582,9 +1483,9 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
1582
1483
|
/**
|
|
1583
1484
|
* callMethodLocally is your old approach for invoking the method in-process.
|
|
1584
1485
|
*/
|
|
1585
|
-
ResolveIOMainServer.prototype.callMethodLocally = function (ws, messageId, method, params
|
|
1486
|
+
ResolveIOMainServer.prototype.callMethodLocally = function (ws, messageId, method, params) {
|
|
1586
1487
|
return __awaiter(this, void 0, void 0, function () {
|
|
1587
|
-
var serverRes,
|
|
1488
|
+
var serverRes, result, err_4;
|
|
1588
1489
|
var _a;
|
|
1589
1490
|
return __generator(this, function (_b) {
|
|
1590
1491
|
switch (_b.label) {
|
|
@@ -1594,10 +1495,9 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
1594
1495
|
hasError: false,
|
|
1595
1496
|
data: null
|
|
1596
1497
|
};
|
|
1597
|
-
startMs = Date.now();
|
|
1598
1498
|
_b.label = 1;
|
|
1599
1499
|
case 1:
|
|
1600
|
-
_b.trys.push([1, 3,
|
|
1500
|
+
_b.trys.push([1, 3, , 4]);
|
|
1601
1501
|
return [4 /*yield*/, (_a = this._methodManager.callMethod).call.apply(_a, __spreadArray([Object.assign({}, this._methodManager, method_manager_1.MethodManager.prototype, {
|
|
1602
1502
|
id_user: ws['id_user'],
|
|
1603
1503
|
user: ws['user'],
|
|
@@ -1607,26 +1507,13 @@ var ResolveIOMainServer = /** @class */ (function () {
|
|
|
1607
1507
|
case 2:
|
|
1608
1508
|
result = _b.sent();
|
|
1609
1509
|
serverRes.data = result;
|
|
1610
|
-
return [3 /*break*/,
|
|
1510
|
+
return [3 /*break*/, 4];
|
|
1611
1511
|
case 3:
|
|
1612
|
-
|
|
1512
|
+
err_4 = _b.sent();
|
|
1613
1513
|
serverRes.hasError = true;
|
|
1614
|
-
serverRes.data =
|
|
1615
|
-
return [3 /*break*/,
|
|
1514
|
+
serverRes.data = err_4 || 'Unknown error';
|
|
1515
|
+
return [3 /*break*/, 4];
|
|
1616
1516
|
case 4:
|
|
1617
|
-
durationMs = Date.now() - startMs;
|
|
1618
|
-
if (durationMs >= this._slowHandlerThresholdMs) {
|
|
1619
|
-
console.log(new Date(), '[Slow Local Method]', {
|
|
1620
|
-
durationMs: durationMs,
|
|
1621
|
-
method: method,
|
|
1622
|
-
route: route || null,
|
|
1623
|
-
id_user: ws['id_user'] || null,
|
|
1624
|
-
user: ws['user'] || null,
|
|
1625
|
-
id_ws: ws['id_socket'] || null
|
|
1626
|
-
});
|
|
1627
|
-
}
|
|
1628
|
-
return [7 /*endfinally*/];
|
|
1629
|
-
case 5:
|
|
1630
1517
|
if (ws && ws.readyState === ws.OPEN) {
|
|
1631
1518
|
this._websocketManager.send(ws, serverRes);
|
|
1632
1519
|
}
|