@resolveio/server-lib 9.1.43 → 9.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/managers/mongo.manager.js +1 -1
- package/managers/mongo.manager.js.map +1 -1
- package/managers/queue-method.manager.js +1 -1
- package/managers/queue-method.manager.js.map +1 -1
- package/managers/subscription.manager.js +281 -98
- package/managers/subscription.manager.js.map +1 -1
- package/managers/subscription.performance.d.ts +27 -0
- package/managers/subscription.performance.js +101 -0
- package/managers/subscription.performance.js.map +1 -0
- package/package.json +1 -1
- package/server-app.d.ts +1 -1
- package/server-app.js +4 -11
- package/server-app.js.map +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/managers/queue-method.manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8EAAkE;AAElE,kFAAsE;AACtE,sFAA0E;AAE1E,wFAA4E;AAC5E,gEAAqD;AACrD,yCAA4D;AAE5D,iDAAoD;AAEpD;IAQC,4BAAY,UAAU;QAAtB,iBAmDC;QAxDO,eAAU,GAAG,EAAE,CAAC;QAChB,kBAAa,GAAG,KAAK,CAAC;QAK7B,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAE9B,WAAW,CAAC;YACX,IAAI,CAAC,KAAI,CAAC,aAAa,EAAE;gBACxB,IAAI,KAAI,CAAC,UAAU,CAAC,MAAM,EAAE;oBAC3B,KAAI,CAAC,aAAa,GAAG,IAAI,CAAC;4CACjB,CAAC;wBACT,IAAI,EAAE,GAAG,KAAI,CAAC,WAAW,CAAC,KAAK,CAAC,KAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;wBAC1D,IAAI,EAAE,IAAI,EAAE,CAAC,UAAU,KAAK,EAAE,CAAC,IAAI,EAAE;4BACpC,IAAI,EAAE,CAAC,cAAc,GAAG,KAAK,EAAE;gCAC9B,IAAI,QAAQ,GAA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from '../collections/queue-flag.collection';\nimport { QueueMethodModel } from '../models/queue-method.model';\nimport { QueueMethods } from '../collections/queue-method.collection';\nimport { QueueResponses } from '../collections/queue-response.collection';\nimport { ServerResponseModel } from '../models/server-response.model';\nimport { MethodResponses } from '../collections/method-response.collection';\nimport { Logs } from '../collections/log.collection';\nimport { getBinarySize, dateReviver } from '../util/common';\nimport ResolveIOMainServer from '../server-app';\nimport { objectIdHexString } from './mongo.manager';\n\nexport class QueueMethodManager {\n\n\tprivate _mainServer: ResolveIOMainServer;\n\tprivate _sendQueue = [];\n\tprivate _runningQueue = false;\n\n\tprivate _runningMethodResponse;\n\n\tconstructor(mainServer) {\n\t\tthis._mainServer = mainServer;\n\n\t\tsetInterval(() => {\n\t\t\tif (!this._runningQueue) {\n\t\t\t\tif (this._sendQueue.length) {\n\t\t\t\t\tthis._runningQueue = true;\n\t\t\t\t\tfor (let i = this._sendQueue.length - 1; i >= 0; i--) {\n\t\t\t\t\t\tlet ws = this._mainServer.getWS(this._sendQueue[i].id_ws);\n\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\tif (ws.bufferedAmount < 20480) {\n\t\t\t\t\t\t\t\tlet sendItem = this._sendQueue.pop();\n\t\t\t\t\t\t\t\tws.send(JSON.stringify(sendItem.response), (error) => {\n\t\t\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\t\t\tconsole.log('Error on WS: ', error);\n\t\t\t\t\t\t\t\t\t\tthis._mainServer.unsubscribeWS(ws);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\tif (sendItem.method !== 'getWOOfflineData' && sendItem.method !== 'getDrivers') {\n\t\t\t\t\t\t\t\t\tLogs.insertOne({\n\t\t\t\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t\t\t\ttype: 'client-response',\n\t\t\t\t\t\t\t\t\t\tcollection: '',\n\t\t\t\t\t\t\t\t\t\tid_document: '',\n\t\t\t\t\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify([sendItem.methodData, sendItem.response])) < 200000 ? JSON.stringify([sendItem.methodData, sendItem.response], null, 2) : 'Too Big',\n\t\t\t\t\t\t\t\t\t\tmethod: sendItem.method,\n\t\t\t\t\t\t\t\t\t\tid_user: ws['id_user'] || '',\n\t\t\t\t\t\t\t\t\t\tuser: ws['user'] || '',\n\t\t\t\t\t\t\t\t\t\tmessageId: sendItem.messageId,\n\t\t\t\t\t\t\t\t\t\troute: ''\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tMethodResponses.create({\n\t\t\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t\t\t__v: 0,\n\t\t\t\t\t\t\t\t\tid_user: sendItem.id_user,\n\t\t\t\t\t\t\t\t\tmessage_id: sendItem.messageId,\n\t\t\t\t\t\t\t\t\tresponse: getBinarySize(JSON.stringify(sendItem.response)) < 200000 ? sendItem.response : {error: 'Too Big'},\n\t\t\t\t\t\t\t\t\tmethod: sendItem.method,\n\t\t\t\t\t\t\t\t\tdate: sendItem.date\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tthis._runningQueue = false;\n\t\t\t\t}\n\t\t\t}\n\t\t}, 1);\n\t}\n\n\tpublic addMethodToQueue(id_methodLatency: string, id_ws: string, id_user: string, user: string, messageDate: Date, messageId: number, method: string, data: any[]) {\n\n\t\t// console.log('Add Method To Queue', method);\n\n\t\tQueueMethods.create({\n\t\t\t_id: objectIdHexString(),\n\t\t\t__v: 0,\n\t\t\tid_ws: id_ws,\n\t\t\tmessageId: messageId,\n\t\t\tmethod: method,\n\t\t\tmethod_data: [],\n\t\t\tmethod_data_string: JSON.stringify(data),\n\t\t\tid_user: id_user,\n\t\t\tuser: user,\n\t\t\tdate: messageDate,\n\t\t\tid_methodLatency: id_methodLatency\n\t\t});\n\t}\n\n\tpublic async runMethodQueue(count?: number) {\n\t\tlet updateCnt = count ? count : await QueueMethods.countDocuments();\n\t\t\n\t\tif (updateCnt) {\n\t\t\t// console.log('Run Method Queue', updateCnt);\n\n\t\t\tQueueFlags.insertOne({_id: 'method-queue', __v: 0}).then(async res => {\n\t\t\t\tif (res) {\n\t\t\t\t\tlet updates = await QueueMethods.find({}, {sort: {createdAt: 1}});\n\n\t\t\t\t\tfor (let i = 0; i < updates.length; i++) {\n\t\t\t\t\t\tlet update = updates[i];\n\n\t\t\t\t\t\tupdate.method_data = JSON.parse(update.method_data_string, dateReviver);\n\n\t\t\t\t\t\tawait this._mainServer.getMethodManager().callMethodQueue(update);\n\t\t\t\t\t\tawait QueueMethods.deleteOne({_id: update._id});\n\t\t\t\t\t}\n\n\t\t\t\t\tQueueFlags.deleteOne({_id: 'method-queue'});\n\n\t\t\t\t\tupdateCnt = await QueueMethods.countDocuments();\n\n\t\t\t\t\tif (updateCnt) {\n\t\t\t\t\t\tthis.runMethodQueue(updateCnt);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}, () => {});\n\t\t}\n\t}\n\n\tpublic addMethodResponse(update: QueueMethodModel, response: ServerResponseModel) {\n\t\tQueueResponses.create({\n\t\t\t_id: objectIdHexString(),\n\t\t\t__v: 0,\n\t\t\tid_ws: update.id_ws,\n\t\t\tid_user: update.id_user,\n\t\t\tuser: update.user,\n\t\t\tmessageId: update.messageId,\n\t\t\tresponse: response,\n\t\t\tmethod: update.method,\n\t\t\tdate: update.date\n\t\t});\n\t}\n\n\tpublic async runMethodResponse() {\n\t\tlet responseCnt = await QueueResponses.countDocuments();\n\n\t\tif (responseCnt && !this._runningMethodResponse) {\n\t\t\tthis._runningMethodResponse = true;\n\n\t\t\tlet wsList = this._mainServer.getWSList();\n\n\t\t\tlet responses = await QueueResponses.find({id_ws: {$in: wsList}});\n\n\t\t\tfor (let i = 0; i < responses.length; i++) {\n\t\t\t\tlet response = responses[i];\n\n\t\t\t\tthis._sendQueue.splice(0, 0, response);\n\n\t\t\t\tQueueResponses.deleteOne({_id: response._id});\n\t\t\t}\n\n\t\t\tthis._runningMethodResponse = false;\n\t\t}\n\t}\n}"]}
|
|
1
|
+
{"version":3,"sources":["../../src/managers/queue-method.manager.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8EAAkE;AAElE,kFAAsE;AACtE,sFAA0E;AAE1E,wFAA4E;AAC5E,gEAAqD;AACrD,yCAA4D;AAE5D,iDAAoD;AAEpD;IAQC,4BAAY,UAAU;QAAtB,iBAmDC;QAxDO,eAAU,GAAG,EAAE,CAAC;QAChB,kBAAa,GAAG,KAAK,CAAC;QAK7B,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAE9B,WAAW,CAAC;YACX,IAAI,CAAC,KAAI,CAAC,aAAa,EAAE;gBACxB,IAAI,KAAI,CAAC,UAAU,CAAC,MAAM,EAAE;oBAC3B,KAAI,CAAC,aAAa,GAAG,IAAI,CAAC;4CACjB,CAAC;wBACT,IAAI,EAAE,GAAG,KAAI,CAAC,WAAW,CAAC,KAAK,CAAC,KAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;wBAC1D,IAAI,EAAE,IAAI,EAAE,CAAC,UAAU,KAAK,EAAE,CAAC,IAAI,EAAE;4BACpC,IAAI,EAAE,CAAC,cAAc,GAAG,KAAK,EAAE;gCAC9B,IAAI,QAAQ,GAAG,KAAI,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC;gCACrC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,UAAC,KAAK;oCAChD,IAAI,KAAK,EAAE;wCACV,OAAO,CAAC,GAAG,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;wCACpC,KAAI,CAAC,WAAW,CAAC,aAAa,CAAC,EAAE,CAAC,CAAC;qC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CAAC,IAAI;SACjB,CAAC,CAAC;IACJ,CAAC;IAEY,8CAAiB,GAA9B;;;;;4BACmB,qBAAM,0CAAc,CAAC,cAAc,EAAE,EAAA;;wBAAnD,WAAW,GAAG,SAAqC;6BAEnD,CAAA,WAAW,IAAI,CAAC,IAAI,CAAC,sBAAsB,CAAA,EAA3C,wBAA2C;wBAC9C,IAAI,CAAC,sBAAsB,GAAG,IAAI,CAAC;wBAE/B,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,SAAS,EAAE,CAAC;wBAE1B,qBAAM,0CAAc,CAAC,IAAI,CAAC,EAAC,KAAK,EAAE,EAAC,GAAG,EAAE,MAAM,EAAC,EAAC,CAAC,EAAA;;wBAA7D,SAAS,GAAG,SAAiD;wBAEjE,KAAS,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;4BACtC,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;4BAE5B,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC;4BAEvC,0CAAc,CAAC,SAAS,CAAC,EAAC,GAAG,EAAE,QAAQ,CAAC,GAAG,EAAC,CAAC,CAAC;yBAC9C;wBAED,IAAI,CAAC,sBAAsB,GAAG,KAAK,CAAC;;;;;;KAErC;IACF,yBAAC;AAAD,CAlJA,AAkJC,IAAA;AAlJY,gDAAkB","file":"queue-method.manager.js","sourcesContent":["import { QueueFlags } from '../collections/queue-flag.collection';\nimport { QueueMethodModel } from '../models/queue-method.model';\nimport { QueueMethods } from '../collections/queue-method.collection';\nimport { QueueResponses } from '../collections/queue-response.collection';\nimport { ServerResponseModel } from '../models/server-response.model';\nimport { MethodResponses } from '../collections/method-response.collection';\nimport { Logs } from '../collections/log.collection';\nimport { getBinarySize, dateReviver } from '../util/common';\nimport ResolveIOMainServer from '../server-app';\nimport { objectIdHexString } from './mongo.manager';\n\nexport class QueueMethodManager {\n\n\tprivate _mainServer: ResolveIOMainServer;\n\tprivate _sendQueue = [];\n\tprivate _runningQueue = false;\n\n\tprivate _runningMethodResponse;\n\n\tconstructor(mainServer) {\n\t\tthis._mainServer = mainServer;\n\n\t\tsetInterval(() => {\n\t\t\tif (!this._runningQueue) {\n\t\t\t\tif (this._sendQueue.length) {\n\t\t\t\t\tthis._runningQueue = true;\n\t\t\t\t\tfor (let i = this._sendQueue.length - 1; i >= 0; i--) {\n\t\t\t\t\t\tlet ws = this._mainServer.getWS(this._sendQueue[i].id_ws);\n\t\t\t\t\t\tif (ws && ws.readyState === ws.OPEN) {\n\t\t\t\t\t\t\tif (ws.bufferedAmount < 20480) {\n\t\t\t\t\t\t\t\tlet sendItem = this._sendQueue.pop();\n\t\t\t\t\t\t\t\tws.send(JSON.stringify(sendItem.response), (error) => {\n\t\t\t\t\t\t\t\t\tif (error) {\n\t\t\t\t\t\t\t\t\t\tconsole.log('Error on WS: ', error);\n\t\t\t\t\t\t\t\t\t\tthis._mainServer.unsubscribeWS(ws);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\tif (sendItem.method !== 'getWOOfflineData' && sendItem.method !== 'getDrivers') {\n\t\t\t\t\t\t\t\t\tLogs.insertOne({\n\t\t\t\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t\t\t\ttype: 'client-response',\n\t\t\t\t\t\t\t\t\t\tcollection: '',\n\t\t\t\t\t\t\t\t\t\tid_document: '',\n\t\t\t\t\t\t\t\t\t\tpayload: getBinarySize(JSON.stringify([sendItem.methodData, sendItem.response])) < 200000 ? JSON.stringify([sendItem.methodData, sendItem.response], null, 2) : 'Too Big',\n\t\t\t\t\t\t\t\t\t\tmethod: sendItem.method,\n\t\t\t\t\t\t\t\t\t\tid_user: ws['id_user'] || '',\n\t\t\t\t\t\t\t\t\t\tuser: ws['user'] || '',\n\t\t\t\t\t\t\t\t\t\tmessageId: sendItem.messageId,\n\t\t\t\t\t\t\t\t\t\troute: ''\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tMethodResponses.create({\n\t\t\t\t\t\t\t\t\t_id: objectIdHexString(),\n\t\t\t\t\t\t\t\t\t__v: 0,\n\t\t\t\t\t\t\t\t\tid_user: sendItem.id_user,\n\t\t\t\t\t\t\t\t\tmessage_id: sendItem.messageId,\n\t\t\t\t\t\t\t\t\tresponse: getBinarySize(JSON.stringify(sendItem.response)) < 200000 ? sendItem.response : {error: 'Too Big'},\n\t\t\t\t\t\t\t\t\tmethod: sendItem.method,\n\t\t\t\t\t\t\t\t\tdate: sendItem.date\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tthis._runningQueue = false;\n\t\t\t\t}\n\t\t\t}\n\t\t}, 10);\n\t}\n\n\tpublic addMethodToQueue(id_methodLatency: string, id_ws: string, id_user: string, user: string, messageDate: Date, messageId: number, method: string, data: any[]) {\n\n\t\t// console.log('Add Method To Queue', method);\n\n\t\tQueueMethods.create({\n\t\t\t_id: objectIdHexString(),\n\t\t\t__v: 0,\n\t\t\tid_ws: id_ws,\n\t\t\tmessageId: messageId,\n\t\t\tmethod: method,\n\t\t\tmethod_data: [],\n\t\t\tmethod_data_string: JSON.stringify(data),\n\t\t\tid_user: id_user,\n\t\t\tuser: user,\n\t\t\tdate: messageDate,\n\t\t\tid_methodLatency: id_methodLatency\n\t\t});\n\t}\n\n\tpublic async runMethodQueue(count?: number) {\n\t\tlet updateCnt = count ? count : await QueueMethods.countDocuments();\n\t\t\n\t\tif (updateCnt) {\n\t\t\t// console.log('Run Method Queue', updateCnt);\n\n\t\t\tQueueFlags.insertOne({_id: 'method-queue', __v: 0}).then(async res => {\n\t\t\t\tif (res) {\n\t\t\t\t\tlet updates = await QueueMethods.find({}, {sort: {createdAt: 1}});\n\n\t\t\t\t\tfor (let i = 0; i < updates.length; i++) {\n\t\t\t\t\t\tlet update = updates[i];\n\n\t\t\t\t\t\tupdate.method_data = JSON.parse(update.method_data_string, dateReviver);\n\n\t\t\t\t\t\tawait this._mainServer.getMethodManager().callMethodQueue(update);\n\t\t\t\t\t\tawait QueueMethods.deleteOne({_id: update._id});\n\t\t\t\t\t}\n\n\t\t\t\t\tQueueFlags.deleteOne({_id: 'method-queue'});\n\n\t\t\t\t\tupdateCnt = await QueueMethods.countDocuments();\n\n\t\t\t\t\tif (updateCnt) {\n\t\t\t\t\t\tthis.runMethodQueue(updateCnt);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}, () => {});\n\t\t}\n\t}\n\n\tpublic addMethodResponse(update: QueueMethodModel, response: ServerResponseModel) {\n\t\tQueueResponses.create({\n\t\t\t_id: objectIdHexString(),\n\t\t\t__v: 0,\n\t\t\tid_ws: update.id_ws,\n\t\t\tid_user: update.id_user,\n\t\t\tuser: update.user,\n\t\t\tmessageId: update.messageId,\n\t\t\tresponse: response,\n\t\t\tmethod: update.method,\n\t\t\tdate: update.date\n\t\t});\n\t}\n\n\tpublic async runMethodResponse() {\n\t\tlet responseCnt = await QueueResponses.countDocuments();\n\n\t\tif (responseCnt && !this._runningMethodResponse) {\n\t\t\tthis._runningMethodResponse = true;\n\n\t\t\tlet wsList = this._mainServer.getWSList();\n\n\t\t\tlet responses = await QueueResponses.find({id_ws: {$in: wsList}});\n\n\t\t\tfor (let i = 0; i < responses.length; i++) {\n\t\t\t\tlet response = responses[i];\n\n\t\t\t\tthis._sendQueue.splice(0, 0, response);\n\n\t\t\t\tQueueResponses.deleteOne({_id: response._id});\n\t\t\t}\n\n\t\t\tthis._runningMethodResponse = false;\n\t\t}\n\t}\n}"]}
|
|
@@ -65,7 +65,20 @@ var mongo_manager_1 = require("./mongo.manager");
|
|
|
65
65
|
var common_1 = require("../util/common");
|
|
66
66
|
var moment = require("moment");
|
|
67
67
|
var NodeCache = require("node-cache");
|
|
68
|
+
// interface CurrentPerformanceMonitor {
|
|
69
|
+
// _id: number;
|
|
70
|
+
// function: string;
|
|
71
|
+
// publication: string;
|
|
72
|
+
// subscriptionData: any[];
|
|
73
|
+
// date_start: Date;
|
|
74
|
+
// date_end: Date;
|
|
75
|
+
// duration: number;
|
|
76
|
+
// result: string;
|
|
77
|
+
// }
|
|
68
78
|
var SubscriptionManager = /** @class */ (function () {
|
|
79
|
+
// private currentPerfomanceMonitor: CurrentPerformanceMonitor[] = [];
|
|
80
|
+
// private idPerformance: number = 0;
|
|
81
|
+
// private performanceThread;
|
|
69
82
|
function SubscriptionManager(mainServer, wss, serverConfig) {
|
|
70
83
|
var _this = this;
|
|
71
84
|
this._publications = {};
|
|
@@ -78,6 +91,21 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
78
91
|
this._cacheId = 1;
|
|
79
92
|
this._mainServer = mainServer;
|
|
80
93
|
this._nodeCache = new NodeCache({ stdTTL: 0, checkperiod: 0 });
|
|
94
|
+
// setTimeout(() => {
|
|
95
|
+
// console.log('Setting up performance thread');
|
|
96
|
+
// this.performanceThread = new Worker(path.join(__dirname, './subscription.performance.js'));
|
|
97
|
+
// this.performanceThread.on('exit', code => {
|
|
98
|
+
// console.error('THREAD EXITED!!!!!!!!!!!!!!!!!!', code);
|
|
99
|
+
// });
|
|
100
|
+
// this.performanceThread.on('error', code => {
|
|
101
|
+
// console.error('THREAD RECV ERROR !!!!!!!!!!!!!!!!!!', code);
|
|
102
|
+
// });
|
|
103
|
+
// }, 5000);
|
|
104
|
+
// setInterval(() => {
|
|
105
|
+
// console.log('Post thread msg');
|
|
106
|
+
// this.performanceThread.postMessage(this.currentPerfomanceMonitor);
|
|
107
|
+
// this.currentPerfomanceMonitor = [];
|
|
108
|
+
// }, 10000);
|
|
81
109
|
this.serverConfig = serverConfig;
|
|
82
110
|
this._wss = wss;
|
|
83
111
|
// Publications
|
|
@@ -98,90 +126,91 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
98
126
|
report_builder_dashboard_builders_1.loadReportBuilderDashboardBuilderPublications(this);
|
|
99
127
|
this.tailOpLog();
|
|
100
128
|
setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
101
|
-
var _loop_1, this_1, i, queueArr, i, mongoQueue, j, client,
|
|
129
|
+
var _loop_1, this_1, i, queueArr, i, mongoQueue, j, client, ws;
|
|
102
130
|
var _this = this;
|
|
103
131
|
return __generator(this, function (_a) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
_this.unsubscribeAll(ws);
|
|
118
|
-
}
|
|
119
|
-
});
|
|
132
|
+
if (!this._runningQueue) {
|
|
133
|
+
if (this._sendQueue.length) {
|
|
134
|
+
// let startDate = new Date();
|
|
135
|
+
this._runningQueue = true;
|
|
136
|
+
_loop_1 = function (i) {
|
|
137
|
+
var ws = this_1._mainServer.getWS(this_1._sendQueue[i].id_ws);
|
|
138
|
+
if (ws && ws.readyState === ws.OPEN) {
|
|
139
|
+
if (ws.bufferedAmount < 20480) {
|
|
140
|
+
var sendItem = this_1._sendQueue.pop();
|
|
141
|
+
ws.send(JSON.stringify(sendItem.data), function (error) {
|
|
142
|
+
if (error) {
|
|
143
|
+
console.log('Error on WS: ', error);
|
|
144
|
+
_this.unsubscribeAll(ws);
|
|
120
145
|
}
|
|
121
|
-
}
|
|
122
|
-
else {
|
|
123
|
-
this_1._sendQueue.splice(i, 1);
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
this_1 = this;
|
|
127
|
-
for (i = this._sendQueue.length - 1; i >= 0; i--) {
|
|
128
|
-
_loop_1(i);
|
|
146
|
+
});
|
|
129
147
|
}
|
|
130
|
-
this._runningQueue = false;
|
|
131
148
|
}
|
|
149
|
+
else {
|
|
150
|
+
this_1._sendQueue.splice(i, 1);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
this_1 = this;
|
|
154
|
+
for (i = this._sendQueue.length - 1; i >= 0; i--) {
|
|
155
|
+
_loop_1(i);
|
|
132
156
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
157
|
+
this._runningQueue = false;
|
|
158
|
+
// let endDate = new Date();
|
|
159
|
+
// this.currentPerfomanceMonitor.push({
|
|
160
|
+
// _id: this.idPerformance++,
|
|
161
|
+
// function: 'sendInterval',
|
|
162
|
+
// publication: '',
|
|
163
|
+
// subscriptionData: [],
|
|
164
|
+
// date_start: startDate,
|
|
165
|
+
// date_end: endDate,
|
|
166
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
167
|
+
// result: 'Done'
|
|
168
|
+
// });
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
queueArr = this._mongoQueue.filter(function (a) { return !a.running; });
|
|
172
|
+
if (queueArr.length) {
|
|
173
|
+
queueArr.forEach(function (entry) {
|
|
174
|
+
entry.running = true;
|
|
175
|
+
});
|
|
176
|
+
// let startDate = new Date();
|
|
177
|
+
for (i = 0; i < queueArr.length; i++) {
|
|
139
178
|
mongoQueue = queueArr[i];
|
|
140
|
-
mongoQueue.
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
if (!(ws['id_socket'] === client.id_socket)) return [3 /*break*/, 5];
|
|
153
|
-
return [4 /*yield*/, this.sendPubDataOnce(ws, client.messageId, mongoQueue.subscription, mongoQueue.type, mongoQueue.collection)];
|
|
154
|
-
case 4:
|
|
155
|
-
_a.sent();
|
|
156
|
-
_a.label = 5;
|
|
157
|
-
case 5:
|
|
158
|
-
k++;
|
|
159
|
-
return [3 /*break*/, 3];
|
|
160
|
-
case 6:
|
|
161
|
-
j++;
|
|
162
|
-
return [3 /*break*/, 2];
|
|
163
|
-
case 7: return [3 /*break*/, 10];
|
|
164
|
-
case 8: return [4 /*yield*/, this.sendPubData(mongoQueue.subscription, mongoQueue.type, mongoQueue.collection)];
|
|
165
|
-
case 9:
|
|
166
|
-
_a.sent();
|
|
167
|
-
_a.label = 10;
|
|
168
|
-
case 10:
|
|
179
|
+
if (this._publications[mongoQueue.subscription.publication].ws_specific) {
|
|
180
|
+
for (j = 0; j < mongoQueue.subscription.clients.length; j++) {
|
|
181
|
+
client = mongoQueue.subscription.clients[j];
|
|
182
|
+
ws = this._mainServer.getWS(client.id_socket);
|
|
183
|
+
if (ws['id_socket'] === client.id_socket) {
|
|
184
|
+
this.sendPubDataOnce(ws, client.messageId, mongoQueue.subscription, mongoQueue.type, mongoQueue.collection);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
this.sendPubData(mongoQueue.subscription, mongoQueue.type, mongoQueue.collection);
|
|
190
|
+
}
|
|
169
191
|
if (mongoQueue.run_again) {
|
|
170
192
|
mongoQueue.running = false;
|
|
171
193
|
mongoQueue.run_again = false;
|
|
172
194
|
}
|
|
173
195
|
else {
|
|
174
|
-
queueArr.splice(queueArr.map(function (a) { return a._id; }).indexOf(mongoQueue._id), 1);
|
|
175
196
|
this._mongoQueue.splice(this._mongoQueue.map(function (a) { return a._id; }).indexOf(mongoQueue._id), 1);
|
|
176
197
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
198
|
+
}
|
|
199
|
+
// let endDate = new Date();
|
|
200
|
+
// this.currentPerfomanceMonitor.push({
|
|
201
|
+
// _id: this.idPerformance++,
|
|
202
|
+
// function: 'mongoQueue',
|
|
203
|
+
// publication: '',
|
|
204
|
+
// subscriptionData: queueArr,
|
|
205
|
+
// date_start: startDate,
|
|
206
|
+
// date_end: endDate,
|
|
207
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
208
|
+
// result: 'Done'
|
|
209
|
+
// });
|
|
182
210
|
}
|
|
211
|
+
return [2 /*return*/];
|
|
183
212
|
});
|
|
184
|
-
}); },
|
|
213
|
+
}); }, 10);
|
|
185
214
|
setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
186
215
|
var _a, userCopy, _loop_2, this_2, i, i, sub, _loop_3, this_3, j;
|
|
187
216
|
return __generator(this, function (_b) {
|
|
@@ -237,19 +266,56 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
237
266
|
}); }, 60000);
|
|
238
267
|
}
|
|
239
268
|
SubscriptionManager.prototype.addToQueue = function (mongoQueue) {
|
|
269
|
+
// let startDate = new Date();
|
|
240
270
|
var _mongoQueue = this._mongoQueue.filter(function (a) { return a.subscription.publication === mongoQueue.subscription.publication && JSON.stringify(a.subscription.subscriptionData) === JSON.stringify(mongoQueue.subscription.subscriptionData); })[0];
|
|
241
271
|
if (_mongoQueue) {
|
|
242
272
|
if (_mongoQueue.running) {
|
|
243
273
|
_mongoQueue.run_again = true;
|
|
274
|
+
// let endDate = new Date();
|
|
275
|
+
// this.currentPerfomanceMonitor.push({
|
|
276
|
+
// _id: this.idPerformance++,
|
|
277
|
+
// function: 'addToQueue',
|
|
278
|
+
// publication: mongoQueue.subscription.publication,
|
|
279
|
+
// subscriptionData: mongoQueue.subscription.subscriptionData,
|
|
280
|
+
// date_start: startDate,
|
|
281
|
+
// date_end: endDate,
|
|
282
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
283
|
+
// result: 'Run Again'
|
|
284
|
+
// });
|
|
244
285
|
}
|
|
286
|
+
// else {
|
|
287
|
+
// let endDate = new Date();
|
|
288
|
+
// this.currentPerfomanceMonitor.push({
|
|
289
|
+
// _id: this.idPerformance++,
|
|
290
|
+
// function: 'addToQueue',
|
|
291
|
+
// publication: mongoQueue.subscription.publication,
|
|
292
|
+
// subscriptionData: mongoQueue.subscription.subscriptionData,
|
|
293
|
+
// date_start: startDate,
|
|
294
|
+
// date_end: endDate,
|
|
295
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
296
|
+
// result: 'Not Running Yet'
|
|
297
|
+
// });
|
|
298
|
+
// }
|
|
245
299
|
}
|
|
246
300
|
else {
|
|
247
301
|
mongoQueue._id = this._mongoQueueId;
|
|
248
302
|
this._mongoQueueId += 1;
|
|
249
303
|
this._mongoQueue.push(mongoQueue);
|
|
304
|
+
// let endDate = new Date();
|
|
305
|
+
// this.currentPerfomanceMonitor.push({
|
|
306
|
+
// _id: this.idPerformance++,
|
|
307
|
+
// function: 'addToQueue',
|
|
308
|
+
// publication: mongoQueue.subscription.publication,
|
|
309
|
+
// subscriptionData: mongoQueue.subscription.subscriptionData,
|
|
310
|
+
// date_start: startDate,
|
|
311
|
+
// date_end: endDate,
|
|
312
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
313
|
+
// result: 'Add to Queue'
|
|
314
|
+
// });
|
|
250
315
|
}
|
|
251
316
|
};
|
|
252
317
|
SubscriptionManager.prototype.invalidatePubsCache = function (collection, type) {
|
|
318
|
+
// let startDate = new Date();
|
|
253
319
|
var collSubs = this._subscriptions.filter(function (a) { return a.collections.includes(collection); });
|
|
254
320
|
for (var i = collSubs.length - 1; i >= 0; i--) {
|
|
255
321
|
var sub = collSubs[i];
|
|
@@ -264,6 +330,17 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
264
330
|
});
|
|
265
331
|
}
|
|
266
332
|
index_1.ResolveIOServer.getMongoManager().invalidateQueryCache(collection);
|
|
333
|
+
// let endDate = new Date();
|
|
334
|
+
// this.currentPerfomanceMonitor.push({
|
|
335
|
+
// _id: this.idPerformance++,
|
|
336
|
+
// function: 'invalidatePubsCache',
|
|
337
|
+
// publication: collection,
|
|
338
|
+
// subscriptionData: [],
|
|
339
|
+
// date_start: startDate,
|
|
340
|
+
// date_end: endDate,
|
|
341
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
342
|
+
// result: 'Done'
|
|
343
|
+
// });
|
|
267
344
|
};
|
|
268
345
|
// Add all files to publications private object
|
|
269
346
|
SubscriptionManager.prototype.publications = function (method) {
|
|
@@ -297,8 +374,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
297
374
|
subscriptionData[_i - 4] = arguments[_i];
|
|
298
375
|
}
|
|
299
376
|
return __awaiter(this, void 0, void 0, function () {
|
|
300
|
-
var pub, valObj, valKeys, rootKeys, i, sub_1,
|
|
301
|
-
var _this = this;
|
|
377
|
+
var pub, valObj, valKeys, rootKeys, i, sub_1, newLoggedInUser;
|
|
302
378
|
return __generator(this, function (_a) {
|
|
303
379
|
pub = this._publications[publication];
|
|
304
380
|
if (!pub) {
|
|
@@ -371,22 +447,31 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
371
447
|
running: false,
|
|
372
448
|
run_again: false
|
|
373
449
|
});
|
|
450
|
+
// let endDate = new Date();
|
|
451
|
+
// this.currentPerfomanceMonitor.push({
|
|
452
|
+
// _id: this.idPerformance++,
|
|
453
|
+
// function: 'subscribe',
|
|
454
|
+
// publication: publication,
|
|
455
|
+
// subscriptionData: subscriptionData,
|
|
456
|
+
// date_start: startDate,
|
|
457
|
+
// date_end: endDate,
|
|
458
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
459
|
+
// result: 'Add to Queue'
|
|
460
|
+
// });
|
|
374
461
|
}
|
|
375
462
|
else if (sub_1.cacheValid) {
|
|
376
463
|
this.sendPubDataOnce(ws, messageId, sub_1, 'newSub', publication);
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
}
|
|
389
|
-
}, 10);
|
|
464
|
+
// let endDate = new Date();
|
|
465
|
+
// this.currentPerfomanceMonitor.push({
|
|
466
|
+
// _id: this.idPerformance++,
|
|
467
|
+
// function: 'subscribe',
|
|
468
|
+
// publication: publication,
|
|
469
|
+
// subscriptionData: subscriptionData,
|
|
470
|
+
// date_start: startDate,
|
|
471
|
+
// date_end: endDate,
|
|
472
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
473
|
+
// result: 'Send Pub Data Once'
|
|
474
|
+
// });
|
|
390
475
|
}
|
|
391
476
|
}
|
|
392
477
|
if (publication === 'appversion') {
|
|
@@ -422,6 +507,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
422
507
|
return __awaiter(this, void 0, void 0, function () {
|
|
423
508
|
var sub, i;
|
|
424
509
|
return __generator(this, function (_a) {
|
|
510
|
+
// let startDate = new Date();
|
|
425
511
|
// console.log('Before');
|
|
426
512
|
// console.dir(this._subscriptions.map(a => a.publication));
|
|
427
513
|
if (!this._publications[publication]) {
|
|
@@ -484,6 +570,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
484
570
|
var _this = this;
|
|
485
571
|
this._oplog = index_1.ResolveIOServer.getMainDB().watch();
|
|
486
572
|
this._oplog.on('change', function (doc) {
|
|
573
|
+
// let startDate = new Date();
|
|
487
574
|
var collection = doc.ns.coll;
|
|
488
575
|
if (collection && !collection.endsWith('.versions') && !collection.startsWith('monitor-') && collection !== 'logs' && collection !== 'log-method-latencies' && collection !== 'log-subscriptions') {
|
|
489
576
|
if (doc.operationType === 'insert') {
|
|
@@ -502,20 +589,59 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
502
589
|
_this._mainServer.getMethodManager().callMethodInternal('sendSupportTicketEmail', doc.documentKey._id);
|
|
503
590
|
}
|
|
504
591
|
}
|
|
505
|
-
|
|
592
|
+
else if (collection !== 'method-responses' && collection !== 'method-calls') {
|
|
593
|
+
_this.invalidatePubsCache(collection, 'insert');
|
|
594
|
+
}
|
|
595
|
+
// let endDate = new Date();
|
|
596
|
+
// this.currentPerfomanceMonitor.push({
|
|
597
|
+
// _id: this.idPerformance++,
|
|
598
|
+
// function: 'oplog',
|
|
599
|
+
// publication: collection,
|
|
600
|
+
// subscriptionData: [doc.documentKey._id],
|
|
601
|
+
// date_start: startDate,
|
|
602
|
+
// date_end: endDate,
|
|
603
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
604
|
+
// result: 'Insert'
|
|
605
|
+
// });
|
|
506
606
|
}
|
|
507
607
|
}
|
|
508
608
|
else if (doc.operationType === 'update' || doc.operationType === 'replace') {
|
|
509
609
|
if (collection === 'cron-jobs') {
|
|
510
610
|
_this._mainServer.getCronManager().checkCronJobsForUpdates();
|
|
511
611
|
}
|
|
512
|
-
|
|
612
|
+
else if (collection !== 'queue-methods' && collection !== 'queue-responses' && collection !== 'method-responses' && collection !== 'method-calls') {
|
|
613
|
+
_this.invalidatePubsCache(collection, 'update');
|
|
614
|
+
}
|
|
615
|
+
// let endDate = new Date();
|
|
616
|
+
// this.currentPerfomanceMonitor.push({
|
|
617
|
+
// _id: this.idPerformance++,
|
|
618
|
+
// function: 'oplog',
|
|
619
|
+
// publication: collection,
|
|
620
|
+
// subscriptionData: [doc.documentKey._id],
|
|
621
|
+
// date_start: startDate,
|
|
622
|
+
// date_end: endDate,
|
|
623
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
624
|
+
// result: 'Update'
|
|
625
|
+
// });
|
|
513
626
|
}
|
|
514
627
|
else if (doc.operationType === 'delete') {
|
|
515
628
|
if (collection === 'cron-jobs') {
|
|
516
629
|
_this._mainServer.getCronManager().checkCronJobsForUpdates();
|
|
517
630
|
}
|
|
518
|
-
|
|
631
|
+
else if (collection !== 'queue-methods' && collection !== 'queue-responses' && collection !== 'method-responses' && collection !== 'method-calls') {
|
|
632
|
+
_this.invalidatePubsCache(collection, 'delete');
|
|
633
|
+
}
|
|
634
|
+
// let endDate = new Date();
|
|
635
|
+
// this.currentPerfomanceMonitor.push({
|
|
636
|
+
// _id: this.idPerformance++,
|
|
637
|
+
// function: 'oplog',
|
|
638
|
+
// publication: collection,
|
|
639
|
+
// subscriptionData: [doc.documentKey._id],
|
|
640
|
+
// date_start: startDate,
|
|
641
|
+
// date_end: endDate,
|
|
642
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
643
|
+
// result: 'Delete'
|
|
644
|
+
// });
|
|
519
645
|
}
|
|
520
646
|
}
|
|
521
647
|
});
|
|
@@ -536,6 +662,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
536
662
|
var _a;
|
|
537
663
|
var _this = this;
|
|
538
664
|
return __generator(this, function (_b) {
|
|
665
|
+
// let startDate = new Date();
|
|
539
666
|
if (!this._publications[subscription.publication].ws_specific) { // Same pub for all users
|
|
540
667
|
if (subscription.cacheId && subscription.cacheValid) {
|
|
541
668
|
serverRes = {
|
|
@@ -549,6 +676,17 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
549
676
|
this._mainServer.getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], 'Error Detected During SendPubDataOnce - Invalid Cache! - ' + subscription.publication + '\n\nData \n' + JSON.stringify(subscription.subscriptionData, null, 2));
|
|
550
677
|
}
|
|
551
678
|
this.sendWS(ws, serverRes);
|
|
679
|
+
// let endDate = new Date();
|
|
680
|
+
// this.currentPerfomanceMonitor.push({
|
|
681
|
+
// _id: this.idPerformance++,
|
|
682
|
+
// function: 'sendPubDataOnce',
|
|
683
|
+
// publication: subscription.publication,
|
|
684
|
+
// subscriptionData: subscription.subscriptionData,
|
|
685
|
+
// date_start: startDate,
|
|
686
|
+
// date_end: endDate,
|
|
687
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
688
|
+
// result: 'Send cache'
|
|
689
|
+
// });
|
|
552
690
|
resolve(true);
|
|
553
691
|
}
|
|
554
692
|
else {
|
|
@@ -568,6 +706,17 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
568
706
|
};
|
|
569
707
|
// console.log('Send Pub Data Once 2', new Date(), 'Success', subscription);
|
|
570
708
|
_this.sendWS(ws, serverRes);
|
|
709
|
+
// let endDate = new Date();
|
|
710
|
+
// this.currentPerfomanceMonitor.push({
|
|
711
|
+
// _id: this.idPerformance++,
|
|
712
|
+
// function: 'sendPubDataOnce',
|
|
713
|
+
// publication: subscription.publication,
|
|
714
|
+
// subscriptionData: subscription.subscriptionData,
|
|
715
|
+
// date_start: startDate,
|
|
716
|
+
// date_end: endDate,
|
|
717
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
718
|
+
// result: 'Send ws spec data'
|
|
719
|
+
// });
|
|
571
720
|
resolve(true);
|
|
572
721
|
}, function (err) {
|
|
573
722
|
var serverRes = {
|
|
@@ -591,6 +740,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
591
740
|
var _a;
|
|
592
741
|
var _this = this;
|
|
593
742
|
return __generator(this, function (_b) {
|
|
743
|
+
// let startDate = new Date();
|
|
594
744
|
if (!subscription.clients.length) {
|
|
595
745
|
if (subscription.cacheId) {
|
|
596
746
|
this._nodeCache.del(subscription.cacheId);
|
|
@@ -611,24 +761,45 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
611
761
|
_this._nodeCache.del(subscription.cacheId);
|
|
612
762
|
}
|
|
613
763
|
_this._subscriptions.splice(_this._subscriptions.findIndex(function (a) { return a.publication === subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscription.subscriptionData); }), 1);
|
|
764
|
+
// let endDate = new Date();
|
|
765
|
+
// this.currentPerfomanceMonitor.push({
|
|
766
|
+
// _id: this.idPerformance++,
|
|
767
|
+
// function: 'sendPubData',
|
|
768
|
+
// publication: subscription.publication,
|
|
769
|
+
// subscriptionData: subscription.subscriptionData,
|
|
770
|
+
// date_start: startDate,
|
|
771
|
+
// date_end: endDate,
|
|
772
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
773
|
+
// result: 'No clients'
|
|
774
|
+
// });
|
|
614
775
|
resolve(false);
|
|
615
776
|
}
|
|
616
777
|
else {
|
|
617
778
|
if (subscription.cacheId && JSON.stringify(_this._nodeCache.get(subscription.cacheId)) === JSON.stringify(res)) {
|
|
618
779
|
subscription.cacheValid = true;
|
|
780
|
+
// let endDate = new Date();
|
|
781
|
+
// this.currentPerfomanceMonitor.push({
|
|
782
|
+
// _id: this.idPerformance++,
|
|
783
|
+
// function: 'sendPubData',
|
|
784
|
+
// publication: subscription.publication,
|
|
785
|
+
// subscriptionData: subscription.subscriptionData,
|
|
786
|
+
// date_start: startDate,
|
|
787
|
+
// date_end: endDate,
|
|
788
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
789
|
+
// result: 'Same cache dont send'
|
|
790
|
+
// });
|
|
619
791
|
}
|
|
620
792
|
else {
|
|
621
793
|
subscription.clients.forEach(function (client) {
|
|
622
|
-
_this.
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
});
|
|
794
|
+
var ws = _this._mainServer.getWS(client.id_socket);
|
|
795
|
+
if (ws) {
|
|
796
|
+
var serverRes = {
|
|
797
|
+
messageId: client.messageId,
|
|
798
|
+
hasError: false,
|
|
799
|
+
data: res
|
|
800
|
+
};
|
|
801
|
+
_this.sendWS(ws, serverRes);
|
|
802
|
+
}
|
|
632
803
|
});
|
|
633
804
|
var nodeCacheSize = _this._nodeCache.getStats().vsize;
|
|
634
805
|
if (nodeCacheSize > 250000000) {
|
|
@@ -656,12 +827,24 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
656
827
|
subscription.cacheId = cacheId;
|
|
657
828
|
subscription.cacheValid = true;
|
|
658
829
|
}
|
|
830
|
+
// let endDate = new Date();
|
|
831
|
+
// this.currentPerfomanceMonitor.push({
|
|
832
|
+
// _id: this.idPerformance++,
|
|
833
|
+
// function: 'sendPubData',
|
|
834
|
+
// publication: subscription.publication,
|
|
835
|
+
// subscriptionData: subscription.subscriptionData,
|
|
836
|
+
// date_start: startDate,
|
|
837
|
+
// date_end: endDate,
|
|
838
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
839
|
+
// result: 'Same data'
|
|
840
|
+
// });
|
|
659
841
|
}
|
|
660
842
|
resolve(true);
|
|
661
843
|
}
|
|
662
844
|
}, function (err) {
|
|
663
845
|
subscription.clients.forEach(function (client) {
|
|
664
|
-
_this.
|
|
846
|
+
var ws = _this._mainServer.getWS(client.id_socket);
|
|
847
|
+
if (ws) {
|
|
665
848
|
if (ws['id_socket'] === client.id_socket) {
|
|
666
849
|
var serverRes = {
|
|
667
850
|
messageId: client.messageId,
|
|
@@ -670,7 +853,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
670
853
|
};
|
|
671
854
|
_this.sendWS(ws, serverRes);
|
|
672
855
|
}
|
|
673
|
-
}
|
|
856
|
+
}
|
|
674
857
|
});
|
|
675
858
|
reject(err);
|
|
676
859
|
});
|