@resolveio/server-lib 12.4.2 → 12.4.4

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.
@@ -30,12 +30,16 @@ export declare class MonitorMongo {
30
30
  export declare class MonitorManagerFunction {
31
31
  private _functionCnt;
32
32
  private _functions;
33
+ private _functionLastCompletedWS;
33
34
  private _functionLastCompleted;
34
35
  constructor();
35
- startMonitorFunction(functionType: MonitorFunctionType, functionName: string, user: string, data: any): number;
36
+ startMonitorFunction(functionType: MonitorFunctionType, functionName: string, user: string, id_socket: string, data: any): number;
36
37
  finishMonitorFunction(id: number): void;
37
38
  getActiveMonitorFunctions(): MonitorFunction[];
38
39
  getLastCompletedMonitorFunction(): MonitorFunction;
40
+ getLastCompletedMonitorFunctionWS(): {
41
+ [id_socket: string]: MonitorFunction;
42
+ };
39
43
  }
40
44
  export declare type MonitorFunctionType = 'Cron Method' | 'Internal Method' | 'Method' | 'User Specific Publication' | 'Publication';
41
45
  export declare class MonitorFunction {
@@ -47,7 +51,8 @@ export declare class MonitorFunction {
47
51
  private _data;
48
52
  startTime: Date;
49
53
  endTime: Date;
54
+ id_socket: string;
50
55
  id: number;
51
- constructor(id: number, functionType: MonitorFunctionType, functionName: string, user: string, data: any);
56
+ constructor(id: number, functionType: MonitorFunctionType, functionName: string, user: string, id_socket: string, data: any);
52
57
  finish(): void;
53
58
  }
@@ -321,9 +321,10 @@ var MonitorManagerFunction = /** @class */ (function () {
321
321
  function MonitorManagerFunction() {
322
322
  this._functionCnt = 0;
323
323
  this._functions = [];
324
+ this._functionLastCompletedWS = {};
324
325
  }
325
- MonitorManagerFunction.prototype.startMonitorFunction = function (functionType, functionName, user, data) {
326
- var newMonitorFunction = new MonitorFunction(this._functionCnt++, functionType, functionName, user, data);
326
+ MonitorManagerFunction.prototype.startMonitorFunction = function (functionType, functionName, user, id_socket, data) {
327
+ var newMonitorFunction = new MonitorFunction(this._functionCnt++, functionType, functionName, user, id_socket, data);
327
328
  this._functions.push(newMonitorFunction);
328
329
  return newMonitorFunction.id;
329
330
  };
@@ -332,6 +333,7 @@ var MonitorManagerFunction = /** @class */ (function () {
332
333
  if (monitor) {
333
334
  monitor.finish();
334
335
  this._functionLastCompleted = monitor;
336
+ this._functionLastCompletedWS[monitor.id_socket] = monitor;
335
337
  this._functions.splice(this._functions.map(function (a) { return a.id; }).indexOf(id), 1);
336
338
  }
337
339
  };
@@ -341,21 +343,26 @@ var MonitorManagerFunction = /** @class */ (function () {
341
343
  MonitorManagerFunction.prototype.getLastCompletedMonitorFunction = function () {
342
344
  return this._functionLastCompleted;
343
345
  };
346
+ MonitorManagerFunction.prototype.getLastCompletedMonitorFunctionWS = function () {
347
+ return this._functionLastCompletedWS;
348
+ };
344
349
  return MonitorManagerFunction;
345
350
  }());
346
351
  exports.MonitorManagerFunction = MonitorManagerFunction;
347
352
  var MonitorFunction = /** @class */ (function () {
348
- function MonitorFunction(id, functionType, functionName, user, data) {
353
+ function MonitorFunction(id, functionType, functionName, user, id_socket, data) {
349
354
  this._timer = null;
350
355
  this._maxDiff = 0;
351
356
  this.startTime = null;
352
357
  this.endTime = null;
358
+ this.id_socket = '';
353
359
  this.id = 0;
354
360
  this.id = id;
355
361
  this.startTime = new Date();
356
362
  this._functionType = functionType;
357
363
  this._functionName = functionName;
358
364
  this._user = user;
365
+ this.id_socket = id_socket;
359
366
  this._data = data;
360
367
  }
361
368
  MonitorFunction.prototype.finish = function () {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/managers/monitor.manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,+BAA0B;AAC1B,gFAAoE;AACpE,sFAA0E;AAC1E,oFAAwE;AACxE,kCAA2C;AAC3C,yCAA0C;AAC1C,iDAAoD;AACpD,IAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAEzB;IAMC,wBAAY,UAAU,EAAE,YAAY;QAH5B,sBAAiB,GAA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AAW,EAAE,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,GAAG,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,aAAa,GAAG,IAAI,GAAG,IAAI,CAAC,aAAa,GAAG,IAAI,GAAG,sDAAsD,GAAG,IAAI,CAAC,QAAQ,GAAG,OAAO,GAAG,IAAI,CAAC,QAAQ,GAAG,IAAI,GAAG,OAAO,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;SAC/e;IACF,CAAC;IACF,sBAAC;AAAD,CArCA,AAqCC,IAAA;AArCY,0CAAe","file":"monitor.manager.js","sourcesContent":["import ResolveIOMainServer from '../server-app';\nimport axios from 'axios';\nimport { MonitorCPUs } from '../collections/monitor-cpu.collection';\nimport { MonitorMemorys } from '../collections/monitor-memory.collection';\nimport { MonitorMongos } from '../collections/monitor-mongo.collection';\nimport { ResolveIOServer } from '../index';\nimport { deepCopy } from '../util/common';\nimport { objectIdHexString } from './mongo.manager';\nconst os = require('os');\n\nexport class MonitorManager {\n\tprivate _mainServer: ResolveIOMainServer;\n\tprivate _serverConfig;\n\tprivate _instanceHostname = '';\n\tprivate _monitorData = [];\n\n\tconstructor(mainServer, serverConfig) {\n\t\tthis._mainServer = mainServer;\n\t\tthis._serverConfig = serverConfig;\n\t\tthis._instanceHostname = os.hostname().replace(/\\./g, '-');\n\n\t\tthis.setupIntervals();\n\t\tthis.setupEventLoop();\n\t}\n\n\t//Create function to get CPU information\n\tcpuAverage() {\n\t\t//Initialise sum of idle and time of cores and fetch CPU info\n\t\tvar totalIdle = 0, totalTick = 0;\n\t\tvar cpus = os.cpus();\n\t\n\t\t//Loop through CPU cores\n\t\tfor(var i = 0, len = cpus.length; i < len; i++) {\n\t\t\t//Select CPU core\n\t\t\tvar cpu = cpus[i];\n\t\t\n\t\t\t//Total up the time in the cores tick\n\t\t\tfor(let type in cpu.times) {\n\t\t\t\ttotalTick += cpu.times[type];\n\t\t\t}\n\t\t\n\t\t\t//Total up the idle time of the core\n\t\t\ttotalIdle += cpu.times.idle;\n\t\t}\n\t\n\t\t//Return the average Idle and Tick times\n\t\treturn {idle: totalIdle / cpus.length, total: totalTick / cpus.length};\n\t}\n\n\tasync setupIntervals() {\n\t\tif (this._serverConfig['ROOT_URL'] !== 'https://resolveio.com' && this._serverConfig['ROOT_URL'] !== 'http://localhost:4200') {\n\t\t\ttry {\n\t\t\t\tlet instanceId = await axios.get('http://169.254.169.254/latest/meta-data/instance-id');\n\n\t\t\t\tsetInterval(async () => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait axios.post('https://backend.resolveio.com/api/health', {\n\t\t\t\t\t\t\ttype: 'application',\n\t\t\t\t\t\t\tid_aws_instance: instanceId.data,\n\t\t\t\t\t\t\tversion: typeof process.env.APP_VERSION === 'number' ? (<any>process.env.APP_VERSION).toString() : process.env.APP_VERSION,\n\t\t\t\t\t\t\tversion_key: process.env.APP_VERSION_KEY\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\tcatch(e) {}\n\t\t\t\t}, 10000);\n\t\t\t}\n\t\t\tcatch(errHealth) {}\n\t\t}\n\n\t\tlet lastCPU = this.cpuAverage();\n\t\t\n\t\tsetInterval(() => {\n\t\t\tlet now = new Date();\n\n\t\t\t//Grab second Measure\n\t\t\tvar endMeasure = this.cpuAverage(); \n\n\t\t\t//Calculate the difference in idle and total time between the measures\n\t\t\tvar idleDifference = endMeasure.idle - lastCPU.idle;\n\t\t\tvar totalDifference = endMeasure.total - lastCPU.total;\n\n\t\t\t//Calculate the average percentage CPU usage\n\t\t\tvar percentageCPU = 1 - idleDifference / totalDifference;\n\t\t\t\n\t\t\tif (this._serverConfig['ROOT_URL'] === 'https://resolveio.com' || this._serverConfig['ROOT_URL'] === 'http://localhost:4200') {\n\t\t\t\tMonitorCPUs.create({\n\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\tmetadata: {\n\t\t\t\t\t\tinstance: this._instanceHostname,\n\t\t\t\t\t\tclient: this._serverConfig['CLIENT_NAME']\n\t\t\t\t\t},\n\t\t\t\t\tdate: now,\n\t\t\t\t\tapp: percentageCPU,\n\t\t\t\t\tsystem: os.loadavg()[0]\n\t\t\t\t});\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthis._monitorData.push({\n\t\t\t\t\tmetadata: {\n\t\t\t\t\t\tinstance: this._instanceHostname,\n\t\t\t\t\t\tclient: this._serverConfig['CLIENT_NAME']\n\t\t\t\t\t},\n\t\t\t\t\tdate: now,\n\t\t\t\t\tapp: percentageCPU,\n\t\t\t\t\tsystem: os.loadavg()[0],\n\t\t\t\t\ttype: 'cpu'\n\t\t\t\t})\n\t\t\t}\n\n\t\t\tlastCPU = endMeasure;\n\n\t\t\tconst memUsage = process.memoryUsage();\n\n\t\t\tif (this._serverConfig['ROOT_URL'] === 'https://resolveio.com' || this._serverConfig['ROOT_URL'] === 'http://localhost:4200') {\n\t\t\t\tMonitorMemorys.create({\n\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\tmetadata: {\n\t\t\t\t\t\tinstance: this._instanceHostname,\n\t\t\t\t\t\tclient: this._serverConfig['CLIENT_NAME']\n\t\t\t\t\t},\n\t\t\t\t\tdate: now,\n\t\t\t\t\tphysical_total: memUsage.heapTotal,\n\t\t\t\t\tphysical_used: memUsage.heapUsed,\n\t\t\t\t\tphysical_free: os.freemem(),\n\t\t\t\t\tvirtual: memUsage.rss,\n\t\t\t\t\tprivate: memUsage.external,\n\t\t\t\t\tphysical: os.totalmem()\n\t\t\t\t});\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthis._monitorData.push({\n\t\t\t\t\tmetadata: {\n\t\t\t\t\t\tinstance: this._instanceHostname,\n\t\t\t\t\t\tclient: this._serverConfig['CLIENT_NAME']\n\t\t\t\t\t},\n\t\t\t\t\tdate: now,\n\t\t\t\t\tphysical_total: memUsage.heapTotal,\n\t\t\t\t\tphysical_used: memUsage.heapUsed,\n\t\t\t\t\tphysical_free: os.freemem(),\n\t\t\t\t\tvirtual: memUsage.rss,\n\t\t\t\t\tprivate: memUsage.external,\n\t\t\t\t\tphysical: os.totalmem(),\n\t\t\t\t\ttype: 'memory'\n\t\t\t\t});\n\t\t\t}\n\t\t}, 3000);\n\t}\n\n\t\n\n\taddMongoTracker(data: MongoMonitorModel) {\n\t\tif (this._serverConfig['ROOT_URL'] === 'https://resolveio.com' || this._serverConfig['ROOT_URL'] === 'http://localhost:4200') {\n\t\t\tif (!data.collection.startsWith('monitor-')) {\n\t\t\t\tMonitorMongos.create({\n\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\tmetadata: {\n\t\t\t\t\t\tinstance: this._instanceHostname,\n\t\t\t\t\t\tclient: this._serverConfig['CLIENT_NAME']\n\t\t\t\t\t},\n\t\t\t\t\tdate: new Date(data.date),\n\t\t\t\t\tmethod: data.method,\n\t\t\t\t\tdoc_collection: data.collection,\n\t\t\t\t\tduration: data.duration,\n\t\t\t\t\tquery: data.query\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tif (this._instanceHostname) {\n\t\t\t\tthis._monitorData.push({\n\t\t\t\t\tmetadata: {\n\t\t\t\t\t\tinstance: this._instanceHostname,\n\t\t\t\t\t\tclient: this._serverConfig['CLIENT_NAME']\n\t\t\t\t\t},\n\t\t\t\t\tdate: new Date(data.date),\n\t\t\t\t\tmethod: data.method,\n\t\t\t\t\tdoc_collection: data.collection,\n\t\t\t\t\tduration: data.duration,\n\t\t\t\t\tquery: data.query,\n\t\t\t\t\ttype: 'mongo'\n\t\t\t\t});\n\t\t\t}\n\t\t}\t\n\t}\n\n\tsetupEventLoop() {\n\t\tsetTimeout(async () => {\n\t\t\tif (this._monitorData.length) {\n\t\t\t\tlet monitorData = deepCopy(this._monitorData);\n\t\t\t\tthis._monitorData = [];\n\n\t\t\t\tlet size = JSON.stringify(monitorData).replace(/[\\[\\]\\,\\\"]/g,'').length * 8;\n\n\t\t\t\tif (size < 45000000) { // 50 MB size limit\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait axios.post('https://backend.resolveio.com/api/monitor', monitorData);\n\t\t\t\t\t}\n\t\t\t\t\tcatch (e) {}\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tlet tmpData = [];\n\t\t\t\t\tfor (let i = 0; i < monitorData.length; i++) {\n\t\t\t\t\t\ttmpData.push(monitorData[i]);\n\t\t\t\t\t\tsize = JSON.stringify(tmpData).replace(/[\\[\\]\\,\\\"]/g,'').length * 8;\n\n\t\t\t\t\t\tif (size > 45000000) {\n\t\t\t\t\t\t\ttmpData.pop();\n\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tawait axios.post('https://backend.resolveio.com/api/monitor', tmpData);\n\n\t\t\t\t\t\t\t\ttmpData = [monitorData[i]];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcatch (e) {}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (tmpData.length) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tawait axios.post('https://backend.resolveio.com/api/monitor', tmpData);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcatch (e) {}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis.setupEventLoop();\n\t\t}, 60000);\n\t}\n}\n\nexport interface MongoMonitorModel {\n\tdate: Date, \n\tmethod: string,\n\tcollection: string,\n\tduration: number,\n\tquery: string\n}\n\nexport class MonitorMongo {\n\tprivate _startTime = 0;\n\tprivate _method = '';\n\tprivate _collection = '';\n\tprivate _query = '';\n\n\tconstructor(method: string, collection: string, query: string) {\n\t\tthis._startTime = Date.now();\n\t\tthis._method = method;\n\t\tthis._collection = collection;\n\t\tthis._query = query;\n\t}\n\n\tpublic finish() {\n\t\tlet endTime = Date.now();\n\n\t\tlet mongoMonitor: MongoMonitorModel = {\n\t\t\tdate: new Date(endTime),\n\t\t\tmethod: this._method,\n\t\t\tcollection: this._collection,\n\t\t\tquery: this._query,\n\t\t\tduration: endTime - this._startTime\n\t\t};\n\n\t\tResolveIOServer.getMainServer().getMonitorManager().addMongoTracker(mongoMonitor);\n\t}\n}\n\nexport class MonitorManagerFunction {\n\tprivate _functionCnt = 0;\n\tprivate _functions: MonitorFunction[] = [];\n\tprivate _functionLastCompleted: MonitorFunction;\n\n\tconstructor() {}\n\n\tstartMonitorFunction(functionType: MonitorFunctionType, functionName: string, user: string, data: any) {\n\t\tlet newMonitorFunction = new MonitorFunction(this._functionCnt++, functionType, functionName, user, data);\n\t\tthis._functions.push(newMonitorFunction);\n\t\treturn newMonitorFunction.id;\n\t}\n\n\tfinishMonitorFunction(id: number) {\n\t\tlet monitor = this._functions.filter(a => a.id === id)[0];\n\t\tif (monitor) {\n\t\t\tmonitor.finish();\n\t\t\tthis._functionLastCompleted = monitor;\n\t\t\tthis._functions.splice(this._functions.map(a => a.id).indexOf(id), 1);\n\t\t}\n\t}\n\n\tgetActiveMonitorFunctions() {\n\t\treturn this._functions;\n\t}\n\n\tgetLastCompletedMonitorFunction() {\n\t\treturn this._functionLastCompleted;\n\t}\n}\n\nexport type MonitorFunctionType = 'Cron Method' | 'Internal Method' | 'Method' | 'User Specific Publication' | 'Publication';\nexport class MonitorFunction {\n\tprivate _timer: NodeJS.Timeout = null;\n\tprivate _maxDiff = 0;\n\tprivate _functionType: MonitorFunctionType;\n\tprivate _functionName: string;\n\tprivate _user: string;\n\tprivate _data: any;\n\tpublic startTime: Date = null;\n\tpublic endTime: Date = null;\n\tpublic id = 0;\n\n\tconstructor(id: number, functionType: MonitorFunctionType, functionName: string, user: string, data: any) {\n\t\tthis.id = id;\n\t\tthis.startTime = new Date();\n\t\tthis._functionType = functionType;\n\t\tthis._functionName = functionName;\n\t\tthis._user = user;\n\t\tthis._data = data;\n\t}\n\n\tpublic finish() {\n\t\tif (this._timer) {\n\t\t\tclearInterval(this._timer);\n\t\t\tthis._timer = null;\n\t\t}\n\n\t\tthis.endTime = new Date();\n\n\t\tlet diff = this.endTime.getTime() - this.startTime.getTime();\n\t\tif (diff > this._maxDiff) {\n\t\t\tthis._maxDiff = diff;\n\t\t}\n\n\t\tif (this._maxDiff >= 5000) {\n\t\t\tResolveIOServer.getMainServer().getMethodManager().sendEmail('dev@resolveio.com', ResolveIOServer.getMainServer().getServerConfig()['CLIENT_NAME'] + ' - Slow ' + this._functionType + ' Detected', '', (this._user ? 'User: ' + this._user + '\\n' : '') + this._functionType + ': ' + this._functionName + '\\n' + 'During this function the event loop did not run for ' + this._maxDiff + ' ms (' + this._maxDiff / 1000 + ' sec)' + (this._data ? '\\n\\nData: ' + JSON.stringify(this._data, null, 2) : ''));\n\t\t}\n\t}\n}"]}
1
+ {"version":3,"sources":["../../src/managers/monitor.manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,+BAA0B;AAC1B,gFAAoE;AACpE,sFAA0E;AAC1E,oFAAwE;AACxE,kCAA2C;AAC3C,yCAA0C;AAC1C,iDAAoD;AACpD,IAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAEzB;IAMC,wBAAY,UAAU,EAAE,YAAY;QAH5B,sBAAiB,GAAG,EAAE,CAAC;QACvB,iBAAY,GAAG,EAAE,CAAC;QAGzB,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAC9B,IAAI,CAAC,aAAa,GAAG,YAAY,CAAC;QAClC,IAAI,CAAC,iBAAiB,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAE3D,IAAI,CAAC,cAAc,EAAE,CAAC;QACtB,IAAI,CAAC,cAAc,EAAE,CAAC;IACvB,CAA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CAAC,KAAK,CAAC,CAAC,CAAC,QAAQ,GAAG,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,aAAa,GAAG,IAAI,GAAG,IAAI,CAAC,aAAa,GAAG,IAAI,GAAG,sDAAsD,GAAG,IAAI,CAAC,QAAQ,GAAG,OAAO,GAAG,IAAI,CAAC,QAAQ,GAAG,IAAI,GAAG,OAAO,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;SAC/e;IACF,CAAC;IACF,sBAAC;AAAD,CAvCA,AAuCC,IAAA;AAvCY,0CAAe","file":"monitor.manager.js","sourcesContent":["import ResolveIOMainServer from '../server-app';\nimport axios from 'axios';\nimport { MonitorCPUs } from '../collections/monitor-cpu.collection';\nimport { MonitorMemorys } from '../collections/monitor-memory.collection';\nimport { MonitorMongos } from '../collections/monitor-mongo.collection';\nimport { ResolveIOServer } from '../index';\nimport { deepCopy } from '../util/common';\nimport { objectIdHexString } from './mongo.manager';\nconst os = require('os');\n\nexport class MonitorManager {\n\tprivate _mainServer: ResolveIOMainServer;\n\tprivate _serverConfig;\n\tprivate _instanceHostname = '';\n\tprivate _monitorData = [];\n\n\tconstructor(mainServer, serverConfig) {\n\t\tthis._mainServer = mainServer;\n\t\tthis._serverConfig = serverConfig;\n\t\tthis._instanceHostname = os.hostname().replace(/\\./g, '-');\n\n\t\tthis.setupIntervals();\n\t\tthis.setupEventLoop();\n\t}\n\n\t//Create function to get CPU information\n\tcpuAverage() {\n\t\t//Initialise sum of idle and time of cores and fetch CPU info\n\t\tvar totalIdle = 0, totalTick = 0;\n\t\tvar cpus = os.cpus();\n\t\n\t\t//Loop through CPU cores\n\t\tfor(var i = 0, len = cpus.length; i < len; i++) {\n\t\t\t//Select CPU core\n\t\t\tvar cpu = cpus[i];\n\t\t\n\t\t\t//Total up the time in the cores tick\n\t\t\tfor(let type in cpu.times) {\n\t\t\t\ttotalTick += cpu.times[type];\n\t\t\t}\n\t\t\n\t\t\t//Total up the idle time of the core\n\t\t\ttotalIdle += cpu.times.idle;\n\t\t}\n\t\n\t\t//Return the average Idle and Tick times\n\t\treturn {idle: totalIdle / cpus.length, total: totalTick / cpus.length};\n\t}\n\n\tasync setupIntervals() {\n\t\tif (this._serverConfig['ROOT_URL'] !== 'https://resolveio.com' && this._serverConfig['ROOT_URL'] !== 'http://localhost:4200') {\n\t\t\ttry {\n\t\t\t\tlet instanceId = await axios.get('http://169.254.169.254/latest/meta-data/instance-id');\n\n\t\t\t\tsetInterval(async () => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait axios.post('https://backend.resolveio.com/api/health', {\n\t\t\t\t\t\t\ttype: 'application',\n\t\t\t\t\t\t\tid_aws_instance: instanceId.data,\n\t\t\t\t\t\t\tversion: typeof process.env.APP_VERSION === 'number' ? (<any>process.env.APP_VERSION).toString() : process.env.APP_VERSION,\n\t\t\t\t\t\t\tversion_key: process.env.APP_VERSION_KEY\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t\tcatch(e) {}\n\t\t\t\t}, 10000);\n\t\t\t}\n\t\t\tcatch(errHealth) {}\n\t\t}\n\n\t\tlet lastCPU = this.cpuAverage();\n\t\t\n\t\tsetInterval(() => {\n\t\t\tlet now = new Date();\n\n\t\t\t//Grab second Measure\n\t\t\tvar endMeasure = this.cpuAverage(); \n\n\t\t\t//Calculate the difference in idle and total time between the measures\n\t\t\tvar idleDifference = endMeasure.idle - lastCPU.idle;\n\t\t\tvar totalDifference = endMeasure.total - lastCPU.total;\n\n\t\t\t//Calculate the average percentage CPU usage\n\t\t\tvar percentageCPU = 1 - idleDifference / totalDifference;\n\t\t\t\n\t\t\tif (this._serverConfig['ROOT_URL'] === 'https://resolveio.com' || this._serverConfig['ROOT_URL'] === 'http://localhost:4200') {\n\t\t\t\tMonitorCPUs.create({\n\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\tmetadata: {\n\t\t\t\t\t\tinstance: this._instanceHostname,\n\t\t\t\t\t\tclient: this._serverConfig['CLIENT_NAME']\n\t\t\t\t\t},\n\t\t\t\t\tdate: now,\n\t\t\t\t\tapp: percentageCPU,\n\t\t\t\t\tsystem: os.loadavg()[0]\n\t\t\t\t});\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthis._monitorData.push({\n\t\t\t\t\tmetadata: {\n\t\t\t\t\t\tinstance: this._instanceHostname,\n\t\t\t\t\t\tclient: this._serverConfig['CLIENT_NAME']\n\t\t\t\t\t},\n\t\t\t\t\tdate: now,\n\t\t\t\t\tapp: percentageCPU,\n\t\t\t\t\tsystem: os.loadavg()[0],\n\t\t\t\t\ttype: 'cpu'\n\t\t\t\t})\n\t\t\t}\n\n\t\t\tlastCPU = endMeasure;\n\n\t\t\tconst memUsage = process.memoryUsage();\n\n\t\t\tif (this._serverConfig['ROOT_URL'] === 'https://resolveio.com' || this._serverConfig['ROOT_URL'] === 'http://localhost:4200') {\n\t\t\t\tMonitorMemorys.create({\n\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\tmetadata: {\n\t\t\t\t\t\tinstance: this._instanceHostname,\n\t\t\t\t\t\tclient: this._serverConfig['CLIENT_NAME']\n\t\t\t\t\t},\n\t\t\t\t\tdate: now,\n\t\t\t\t\tphysical_total: memUsage.heapTotal,\n\t\t\t\t\tphysical_used: memUsage.heapUsed,\n\t\t\t\t\tphysical_free: os.freemem(),\n\t\t\t\t\tvirtual: memUsage.rss,\n\t\t\t\t\tprivate: memUsage.external,\n\t\t\t\t\tphysical: os.totalmem()\n\t\t\t\t});\n\t\t\t}\n\t\t\telse {\n\t\t\t\tthis._monitorData.push({\n\t\t\t\t\tmetadata: {\n\t\t\t\t\t\tinstance: this._instanceHostname,\n\t\t\t\t\t\tclient: this._serverConfig['CLIENT_NAME']\n\t\t\t\t\t},\n\t\t\t\t\tdate: now,\n\t\t\t\t\tphysical_total: memUsage.heapTotal,\n\t\t\t\t\tphysical_used: memUsage.heapUsed,\n\t\t\t\t\tphysical_free: os.freemem(),\n\t\t\t\t\tvirtual: memUsage.rss,\n\t\t\t\t\tprivate: memUsage.external,\n\t\t\t\t\tphysical: os.totalmem(),\n\t\t\t\t\ttype: 'memory'\n\t\t\t\t});\n\t\t\t}\n\t\t}, 3000);\n\t}\n\n\t\n\n\taddMongoTracker(data: MongoMonitorModel) {\n\t\tif (this._serverConfig['ROOT_URL'] === 'https://resolveio.com' || this._serverConfig['ROOT_URL'] === 'http://localhost:4200') {\n\t\t\tif (!data.collection.startsWith('monitor-')) {\n\t\t\t\tMonitorMongos.create({\n\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\tmetadata: {\n\t\t\t\t\t\tinstance: this._instanceHostname,\n\t\t\t\t\t\tclient: this._serverConfig['CLIENT_NAME']\n\t\t\t\t\t},\n\t\t\t\t\tdate: new Date(data.date),\n\t\t\t\t\tmethod: data.method,\n\t\t\t\t\tdoc_collection: data.collection,\n\t\t\t\t\tduration: data.duration,\n\t\t\t\t\tquery: data.query\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\telse {\n\t\t\tif (this._instanceHostname) {\n\t\t\t\tthis._monitorData.push({\n\t\t\t\t\tmetadata: {\n\t\t\t\t\t\tinstance: this._instanceHostname,\n\t\t\t\t\t\tclient: this._serverConfig['CLIENT_NAME']\n\t\t\t\t\t},\n\t\t\t\t\tdate: new Date(data.date),\n\t\t\t\t\tmethod: data.method,\n\t\t\t\t\tdoc_collection: data.collection,\n\t\t\t\t\tduration: data.duration,\n\t\t\t\t\tquery: data.query,\n\t\t\t\t\ttype: 'mongo'\n\t\t\t\t});\n\t\t\t}\n\t\t}\t\n\t}\n\n\tsetupEventLoop() {\n\t\tsetTimeout(async () => {\n\t\t\tif (this._monitorData.length) {\n\t\t\t\tlet monitorData = deepCopy(this._monitorData);\n\t\t\t\tthis._monitorData = [];\n\n\t\t\t\tlet size = JSON.stringify(monitorData).replace(/[\\[\\]\\,\\\"]/g,'').length * 8;\n\n\t\t\t\tif (size < 45000000) { // 50 MB size limit\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait axios.post('https://backend.resolveio.com/api/monitor', monitorData);\n\t\t\t\t\t}\n\t\t\t\t\tcatch (e) {}\n\t\t\t\t}\n\t\t\t\telse {\n\t\t\t\t\tlet tmpData = [];\n\t\t\t\t\tfor (let i = 0; i < monitorData.length; i++) {\n\t\t\t\t\t\ttmpData.push(monitorData[i]);\n\t\t\t\t\t\tsize = JSON.stringify(tmpData).replace(/[\\[\\]\\,\\\"]/g,'').length * 8;\n\n\t\t\t\t\t\tif (size > 45000000) {\n\t\t\t\t\t\t\ttmpData.pop();\n\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tawait axios.post('https://backend.resolveio.com/api/monitor', tmpData);\n\n\t\t\t\t\t\t\t\ttmpData = [monitorData[i]];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcatch (e) {}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (tmpData.length) {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tawait axios.post('https://backend.resolveio.com/api/monitor', tmpData);\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcatch (e) {}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tthis.setupEventLoop();\n\t\t}, 60000);\n\t}\n}\n\nexport interface MongoMonitorModel {\n\tdate: Date, \n\tmethod: string,\n\tcollection: string,\n\tduration: number,\n\tquery: string\n}\n\nexport class MonitorMongo {\n\tprivate _startTime = 0;\n\tprivate _method = '';\n\tprivate _collection = '';\n\tprivate _query = '';\n\n\tconstructor(method: string, collection: string, query: string) {\n\t\tthis._startTime = Date.now();\n\t\tthis._method = method;\n\t\tthis._collection = collection;\n\t\tthis._query = query;\n\t}\n\n\tpublic finish() {\n\t\tlet endTime = Date.now();\n\n\t\tlet mongoMonitor: MongoMonitorModel = {\n\t\t\tdate: new Date(endTime),\n\t\t\tmethod: this._method,\n\t\t\tcollection: this._collection,\n\t\t\tquery: this._query,\n\t\t\tduration: endTime - this._startTime\n\t\t};\n\n\t\tResolveIOServer.getMainServer().getMonitorManager().addMongoTracker(mongoMonitor);\n\t}\n}\n\nexport class MonitorManagerFunction {\n\tprivate _functionCnt = 0;\n\tprivate _functions: MonitorFunction[] = [];\n\tprivate _functionLastCompletedWS: {\n\t\t[id_socket: string]: MonitorFunction;\n\t} = {};\n\tprivate _functionLastCompleted: MonitorFunction;\n\n\tconstructor() {}\n\n\tstartMonitorFunction(functionType: MonitorFunctionType, functionName: string, user: string, id_socket: string, data: any) {\n\t\tlet newMonitorFunction = new MonitorFunction(this._functionCnt++, functionType, functionName, user, id_socket, data);\n\t\tthis._functions.push(newMonitorFunction);\n\t\treturn newMonitorFunction.id;\n\t}\n\n\tfinishMonitorFunction(id: number) {\n\t\tlet monitor = this._functions.filter(a => a.id === id)[0];\n\t\tif (monitor) {\n\t\t\tmonitor.finish();\n\t\t\tthis._functionLastCompleted = monitor;\n\t\t\tthis._functionLastCompletedWS[monitor.id_socket] = monitor;\n\t\t\tthis._functions.splice(this._functions.map(a => a.id).indexOf(id), 1);\n\t\t}\n\t}\n\n\tgetActiveMonitorFunctions() {\n\t\treturn this._functions;\n\t}\n\n\tgetLastCompletedMonitorFunction() {\n\t\treturn this._functionLastCompleted;\n\t}\n\t\n\tgetLastCompletedMonitorFunctionWS() {\n\t\treturn this._functionLastCompletedWS;\n\t}\n}\n\nexport type MonitorFunctionType = 'Cron Method' | 'Internal Method' | 'Method' | 'User Specific Publication' | 'Publication';\nexport class MonitorFunction {\n\tprivate _timer: NodeJS.Timeout = null;\n\tprivate _maxDiff = 0;\n\tprivate _functionType: MonitorFunctionType;\n\tprivate _functionName: string;\n\tprivate _user: string;\n\tprivate _data: any;\n\tpublic startTime: Date = null;\n\tpublic endTime: Date = null;\n\tpublic id_socket = '';\n\tpublic id = 0;\n\n\tconstructor(id: number, functionType: MonitorFunctionType, functionName: string, user: string, id_socket: string, data: any) {\n\t\tthis.id = id;\n\t\tthis.startTime = new Date();\n\t\tthis._functionType = functionType;\n\t\tthis._functionName = functionName;\n\t\tthis._user = user;\n\t\tthis.id_socket = id_socket;\n\t\tthis._data = data;\n\t}\n\n\tpublic finish() {\n\t\tif (this._timer) {\n\t\t\tclearInterval(this._timer);\n\t\t\tthis._timer = null;\n\t\t}\n\n\t\tthis.endTime = new Date();\n\n\t\tlet diff = this.endTime.getTime() - this.startTime.getTime();\n\t\tif (diff > this._maxDiff) {\n\t\t\tthis._maxDiff = diff;\n\t\t}\n\n\t\tif (this._maxDiff >= 5000) {\n\t\t\tResolveIOServer.getMainServer().getMethodManager().sendEmail('dev@resolveio.com', ResolveIOServer.getMainServer().getServerConfig()['CLIENT_NAME'] + ' - Slow ' + this._functionType + ' Detected', '', (this._user ? 'User: ' + this._user + '\\n' : '') + this._functionType + ': ' + this._functionName + '\\n' + 'During this function the event loop did not run for ' + this._maxDiff + ' ms (' + this._maxDiff / 1000 + ' sec)' + (this._data ? '\\n\\nData: ' + JSON.stringify(this._data, null, 2) : ''));\n\t\t}\n\t}\n}"]}
@@ -170,37 +170,31 @@ 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 _loop_1, this_1, i, queueArr, _loop_2, this_2, i;
173
+ var ws_1, sendItem, queueArr, mongoQueue_1, promises, _loop_1, this_1, j;
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
- _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);
179
+ // let startDate = new Date();
180
+ this._debugSendQueueHits += 1;
181
+ ws_1 = this._mainServer.getWS(this._sendQueue[this._sendQueue.length - 1].id_ws);
182
+ if (ws_1 && ws_1.readyState === ws_1.OPEN) {
183
+ if (ws_1.bufferedAmount < 20480) {
184
+ sendItem = this._sendQueue.pop();
185
+ ws_1.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_1['user'], ws_1['id_socket'], 1);
192
190
  }
193
- });
194
- }
195
- }
196
- else {
197
- this_1._sendQueue.splice(i, 1);
191
+ _this.unsubscribeAll(ws_1);
192
+ }
193
+ });
198
194
  }
199
- };
200
- this_1 = this;
201
- // let startDate = new Date();
202
- for (i = this._sendQueue.length - 1; i >= 0; i--) {
203
- _loop_1(i);
195
+ }
196
+ else {
197
+ this._sendQueue.splice(this._sendQueue.length - 1, 1);
204
198
  }
205
199
  // let endDate = new Date();
206
200
  // this.currentPerfomanceMonitor.push({
@@ -216,71 +210,63 @@ var SubscriptionManager = /** @class */ (function () {
216
210
  }
217
211
  queueArr = this._mongoQueue.filter(function (a) { return !a.running; });
218
212
  if (queueArr.length) {
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
- });
231
- }
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
- }));
245
- }
246
- };
247
- for (var j = 0; j < mongoQueue.subscription.clients.length; j++) {
248
- _loop_3(j);
213
+ this._debugMongoQueueHits += 1;
214
+ mongoQueue_1 = queueArr[queueArr.length - 1];
215
+ mongoQueue_1.running = true;
216
+ if (!this._debugMongoQueueCollections.some(function (a) { return a.collection === mongoQueue_1.collection && a.publication === mongoQueue_1.subscription.publication; })) {
217
+ this._debugMongoQueueCollections.push({
218
+ collection: mongoQueue_1.collection,
219
+ publication: mongoQueue_1.subscription.publication,
220
+ hits: 1
221
+ });
222
+ }
223
+ else {
224
+ this._debugMongoQueueCollections.filter(function (a) { return a.collection === mongoQueue_1.collection && a.publication === mongoQueue_1.subscription.publication; })[0].hits += 1;
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
+ }));
249
236
  }
250
- Promise.all(promises).then(function () {
251
- if (mongoQueue.run_again) {
252
- mongoQueue.running = false;
253
- mongoQueue.run_again = false;
254
- }
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
- });
237
+ };
238
+ this_1 = this;
239
+ for (j = 0; j < mongoQueue_1.subscription.clients.length; j++) {
240
+ _loop_1(j);
261
241
  }
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
- }
242
+ Promise.all(promises).then(function () {
243
+ if (mongoQueue_1.run_again) {
244
+ mongoQueue_1.running = false;
245
+ mongoQueue_1.run_again = false;
246
+ }
247
+ else {
248
+ if (_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue_1._id) >= 0) {
249
+ _this._mongoQueue.splice(_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue_1._id), 1);
272
250
  }
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);
251
+ }
252
+ });
253
+ }
254
+ else {
255
+ this.sendDataToAll(mongoQueue_1).then(function () {
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);
276
263
  }
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);
264
+ }
265
+ }, function () {
266
+ if (_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue_1._id) >= 0) {
267
+ _this._mongoQueue.splice(_this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue_1._id), 1);
268
+ }
269
+ });
284
270
  }
285
271
  // let endDate = new Date();
286
272
  // this.currentPerfomanceMonitor.push({
@@ -300,7 +286,7 @@ var SubscriptionManager = /** @class */ (function () {
300
286
  });
301
287
  }); }, 50);
302
288
  setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
303
- var _a, userCopy, _loop_4, this_3, i, i, sub, _loop_5, this_4, j;
289
+ var _a, userCopy, _loop_2, this_2, i, i, sub, _loop_3, this_3, j;
304
290
  return __generator(this, function (_b) {
305
291
  switch (_b.label) {
306
292
  case 0:
@@ -309,17 +295,17 @@ var SubscriptionManager = /** @class */ (function () {
309
295
  case 1:
310
296
  _a._loggedInUsers = _b.sent();
311
297
  userCopy = common_1.deepCopy(this._loggedInUsers);
312
- _loop_4 = function (i) {
298
+ _loop_2 = function (i) {
313
299
  var loggedInUser = userCopy[i];
314
300
  if (!loggedInUser.date || Date.now() - loggedInUser.date.getTime() > 120000) {
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);
301
+ if (this_2._mainServer.getWS(loggedInUser.id_ws)) {
302
+ if (this_2.getEnableDebug()) {
303
+ console.log(new Date(), 'Sub Manager', 'Unsub WS', this_2._mainServer.getWS(loggedInUser.id_ws)['user'], this_2._mainServer.getWS(loggedInUser.id_ws)['id_socket'], 2);
318
304
  }
319
- this_3.unsubscribeAll(this_3._mainServer.getWS(loggedInUser.id_ws));
305
+ this_2.unsubscribeAll(this_2._mainServer.getWS(loggedInUser.id_ws));
320
306
  }
321
307
  else {
322
- this_3._subscriptions.forEach(function (sub) {
308
+ this_2._subscriptions.forEach(function (sub) {
323
309
  for (var j = sub.clients.length - 1; j >= 0; j--) {
324
310
  var client = sub.clients[j];
325
311
  if (client.id_socket === loggedInUser.id_ws) {
@@ -328,27 +314,27 @@ var SubscriptionManager = /** @class */ (function () {
328
314
  }
329
315
  });
330
316
  logged_in_users_collection_1.LoggedInUsers.deleteOne({ _id: loggedInUser._id });
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);
317
+ if (this_2._loggedInUsers.findIndex(function (a) { return a._id === loggedInUser._id; }) >= 0) {
318
+ this_2._loggedInUsers.splice(this_2._loggedInUsers.findIndex(function (a) { return a._id === loggedInUser._id; }), 1);
333
319
  }
334
320
  }
335
321
  }
336
322
  };
337
- this_3 = this;
323
+ this_2 = this;
338
324
  for (i = this._loggedInUsers.length - 1; i >= 0; i--) {
339
- _loop_4(i);
325
+ _loop_2(i);
340
326
  }
341
327
  for (i = 0; i < this._subscriptions.length; i++) {
342
328
  sub = this._subscriptions[i];
343
- _loop_5 = function (j) {
329
+ _loop_3 = function (j) {
344
330
  var client = sub.clients[j];
345
- if (!this_4._loggedInUsers.some(function (a) { return a.id_ws === client.id_socket; })) {
331
+ if (!this_3._loggedInUsers.some(function (a) { return a.id_ws === client.id_socket; })) {
346
332
  sub.clients.splice(j, 1);
347
333
  }
348
334
  };
349
- this_4 = this;
335
+ this_3 = this;
350
336
  for (j = sub.clients.length - 1; j >= 0; j--) {
351
- _loop_5(j);
337
+ _loop_3(j);
352
338
  }
353
339
  }
354
340
  return [2 /*return*/];
@@ -895,7 +881,7 @@ var SubscriptionManager = /** @class */ (function () {
895
881
  }
896
882
  }
897
883
  else { // Pub is different for each user (Look at users publication) [MUCH SLOWER, RE-RUNS FOR EACH USER]
898
- monitor_1 = this._monitorManagerFunction.startMonitorFunction('User Specific Publication', subscription.publication, '', subscription.subscriptionData);
884
+ monitor_1 = this._monitorManagerFunction.startMonitorFunction('User Specific Publication', subscription.publication, '', '', subscription.subscriptionData);
899
885
  (_a = this._publications[subscription.publication].function).call.apply(_a, __spreadArrays([Object.assign({}, this, SubscriptionManager.prototype), ws['id_user']], subscription.subscriptionData)).then(function (res) {
900
886
  _this._monitorManagerFunction.finishMonitorFunction(monitor_1);
901
887
  var serverRes = {
@@ -957,7 +943,7 @@ var SubscriptionManager = /** @class */ (function () {
957
943
  if (mongoQueue.subscription.publication !== 'superadminAPM' && mongoQueue.subscription.publication !== 'loggedInUsers') {
958
944
  this._mainServer.getMethodManager().callMethodInternal.call(this._mainServer.getMethodManager(), 'insertSubscriptionLog', mongoQueue.type, mongoQueue.subscription.publication, mongoQueue.collection, JSON.stringify(mongoQueue.subscription.subscriptionData));
959
945
  }
960
- monitor_2 = this._monitorManagerFunction.startMonitorFunction('Publication', mongoQueue.subscription.publication, '', mongoQueue.subscription.subscriptionData);
946
+ monitor_2 = this._monitorManagerFunction.startMonitorFunction('Publication', mongoQueue.subscription.publication, '', '', mongoQueue.subscription.subscriptionData);
961
947
  (_a = this._publications[mongoQueue.subscription.publication].function).call.apply(_a, __spreadArrays([Object.assign({}, this, SubscriptionManager.prototype)], mongoQueue.subscription.subscriptionData)).then(function (res) {
962
948
  _this._monitorManagerFunction.finishMonitorFunction(monitor_2);
963
949
  if (!mongoQueue.subscription.clients.length) {