@resolveio/server-lib 9.1.43 → 9.1.44
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 +298 -88
- 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) {
|
|
@@ -371,9 +448,31 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
371
448
|
running: false,
|
|
372
449
|
run_again: false
|
|
373
450
|
});
|
|
451
|
+
// let endDate = new Date();
|
|
452
|
+
// this.currentPerfomanceMonitor.push({
|
|
453
|
+
// _id: this.idPerformance++,
|
|
454
|
+
// function: 'subscribe',
|
|
455
|
+
// publication: publication,
|
|
456
|
+
// subscriptionData: subscriptionData,
|
|
457
|
+
// date_start: startDate,
|
|
458
|
+
// date_end: endDate,
|
|
459
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
460
|
+
// result: 'Add to Queue'
|
|
461
|
+
// });
|
|
374
462
|
}
|
|
375
463
|
else if (sub_1.cacheValid) {
|
|
376
464
|
this.sendPubDataOnce(ws, messageId, sub_1, 'newSub', publication);
|
|
465
|
+
// let endDate = new Date();
|
|
466
|
+
// this.currentPerfomanceMonitor.push({
|
|
467
|
+
// _id: this.idPerformance++,
|
|
468
|
+
// function: 'subscribe',
|
|
469
|
+
// publication: publication,
|
|
470
|
+
// subscriptionData: subscriptionData,
|
|
471
|
+
// date_start: startDate,
|
|
472
|
+
// date_end: endDate,
|
|
473
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
474
|
+
// result: 'Send Pub Data Once'
|
|
475
|
+
// });
|
|
377
476
|
}
|
|
378
477
|
else {
|
|
379
478
|
intervalCnt_1 = 0;
|
|
@@ -381,12 +480,25 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
381
480
|
if (sub_1.cacheValid) {
|
|
382
481
|
_this.sendPubDataOnce(ws, messageId, sub_1, 'newSub', publication);
|
|
383
482
|
clearInterval(subInterval_1);
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
483
|
+
// let endDate = new Date();
|
|
484
|
+
// this.currentPerfomanceMonitor.push({
|
|
485
|
+
// _id: this.idPerformance++,
|
|
486
|
+
// function: 'subscribe',
|
|
487
|
+
// publication: publication,
|
|
488
|
+
// subscriptionData: subscriptionData,
|
|
489
|
+
// date_start: startDate,
|
|
490
|
+
// date_end: endDate,
|
|
491
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
492
|
+
// result: 'Wait for sub to complete then send cache'
|
|
493
|
+
// });
|
|
494
|
+
}
|
|
495
|
+
if (intervalCnt_1 > 10) {
|
|
496
|
+
_this._mainServer.getMethodManager().sendEmail('dev@resolveio.com', 'SERVER - Error Detected - ' + _this.serverConfig['CLIENT_NAME'], 'Error Detected During Subscribe - Waiting and No Cache! - ' + publication + '\n\nData \n' + JSON.stringify(sub_1.subscriptionData, null, 2));
|
|
497
|
+
}
|
|
498
|
+
else {
|
|
499
|
+
intervalCnt_1 += 1;
|
|
388
500
|
}
|
|
389
|
-
},
|
|
501
|
+
}, 100);
|
|
390
502
|
}
|
|
391
503
|
}
|
|
392
504
|
if (publication === 'appversion') {
|
|
@@ -422,6 +534,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
422
534
|
return __awaiter(this, void 0, void 0, function () {
|
|
423
535
|
var sub, i;
|
|
424
536
|
return __generator(this, function (_a) {
|
|
537
|
+
// let startDate = new Date();
|
|
425
538
|
// console.log('Before');
|
|
426
539
|
// console.dir(this._subscriptions.map(a => a.publication));
|
|
427
540
|
if (!this._publications[publication]) {
|
|
@@ -484,6 +597,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
484
597
|
var _this = this;
|
|
485
598
|
this._oplog = index_1.ResolveIOServer.getMainDB().watch();
|
|
486
599
|
this._oplog.on('change', function (doc) {
|
|
600
|
+
// let startDate = new Date();
|
|
487
601
|
var collection = doc.ns.coll;
|
|
488
602
|
if (collection && !collection.endsWith('.versions') && !collection.startsWith('monitor-') && collection !== 'logs' && collection !== 'log-method-latencies' && collection !== 'log-subscriptions') {
|
|
489
603
|
if (doc.operationType === 'insert') {
|
|
@@ -502,20 +616,59 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
502
616
|
_this._mainServer.getMethodManager().callMethodInternal('sendSupportTicketEmail', doc.documentKey._id);
|
|
503
617
|
}
|
|
504
618
|
}
|
|
505
|
-
|
|
619
|
+
else if (collection !== 'method-responses' && collection !== 'method-calls') {
|
|
620
|
+
_this.invalidatePubsCache(collection, 'insert');
|
|
621
|
+
}
|
|
622
|
+
// let endDate = new Date();
|
|
623
|
+
// this.currentPerfomanceMonitor.push({
|
|
624
|
+
// _id: this.idPerformance++,
|
|
625
|
+
// function: 'oplog',
|
|
626
|
+
// publication: collection,
|
|
627
|
+
// subscriptionData: [doc.documentKey._id],
|
|
628
|
+
// date_start: startDate,
|
|
629
|
+
// date_end: endDate,
|
|
630
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
631
|
+
// result: 'Insert'
|
|
632
|
+
// });
|
|
506
633
|
}
|
|
507
634
|
}
|
|
508
635
|
else if (doc.operationType === 'update' || doc.operationType === 'replace') {
|
|
509
636
|
if (collection === 'cron-jobs') {
|
|
510
637
|
_this._mainServer.getCronManager().checkCronJobsForUpdates();
|
|
511
638
|
}
|
|
512
|
-
|
|
639
|
+
else if (collection !== 'queue-methods' && collection !== 'queue-responses' && collection !== 'method-responses' && collection !== 'method-calls') {
|
|
640
|
+
_this.invalidatePubsCache(collection, 'update');
|
|
641
|
+
}
|
|
642
|
+
// let endDate = new Date();
|
|
643
|
+
// this.currentPerfomanceMonitor.push({
|
|
644
|
+
// _id: this.idPerformance++,
|
|
645
|
+
// function: 'oplog',
|
|
646
|
+
// publication: collection,
|
|
647
|
+
// subscriptionData: [doc.documentKey._id],
|
|
648
|
+
// date_start: startDate,
|
|
649
|
+
// date_end: endDate,
|
|
650
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
651
|
+
// result: 'Update'
|
|
652
|
+
// });
|
|
513
653
|
}
|
|
514
654
|
else if (doc.operationType === 'delete') {
|
|
515
655
|
if (collection === 'cron-jobs') {
|
|
516
656
|
_this._mainServer.getCronManager().checkCronJobsForUpdates();
|
|
517
657
|
}
|
|
518
|
-
|
|
658
|
+
else if (collection !== 'queue-methods' && collection !== 'queue-responses' && collection !== 'method-responses' && collection !== 'method-calls') {
|
|
659
|
+
_this.invalidatePubsCache(collection, 'delete');
|
|
660
|
+
}
|
|
661
|
+
// let endDate = new Date();
|
|
662
|
+
// this.currentPerfomanceMonitor.push({
|
|
663
|
+
// _id: this.idPerformance++,
|
|
664
|
+
// function: 'oplog',
|
|
665
|
+
// publication: collection,
|
|
666
|
+
// subscriptionData: [doc.documentKey._id],
|
|
667
|
+
// date_start: startDate,
|
|
668
|
+
// date_end: endDate,
|
|
669
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
670
|
+
// result: 'Delete'
|
|
671
|
+
// });
|
|
519
672
|
}
|
|
520
673
|
}
|
|
521
674
|
});
|
|
@@ -536,6 +689,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
536
689
|
var _a;
|
|
537
690
|
var _this = this;
|
|
538
691
|
return __generator(this, function (_b) {
|
|
692
|
+
// let startDate = new Date();
|
|
539
693
|
if (!this._publications[subscription.publication].ws_specific) { // Same pub for all users
|
|
540
694
|
if (subscription.cacheId && subscription.cacheValid) {
|
|
541
695
|
serverRes = {
|
|
@@ -549,6 +703,17 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
549
703
|
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
704
|
}
|
|
551
705
|
this.sendWS(ws, serverRes);
|
|
706
|
+
// let endDate = new Date();
|
|
707
|
+
// this.currentPerfomanceMonitor.push({
|
|
708
|
+
// _id: this.idPerformance++,
|
|
709
|
+
// function: 'sendPubDataOnce',
|
|
710
|
+
// publication: subscription.publication,
|
|
711
|
+
// subscriptionData: subscription.subscriptionData,
|
|
712
|
+
// date_start: startDate,
|
|
713
|
+
// date_end: endDate,
|
|
714
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
715
|
+
// result: 'Send cache'
|
|
716
|
+
// });
|
|
552
717
|
resolve(true);
|
|
553
718
|
}
|
|
554
719
|
else {
|
|
@@ -568,6 +733,17 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
568
733
|
};
|
|
569
734
|
// console.log('Send Pub Data Once 2', new Date(), 'Success', subscription);
|
|
570
735
|
_this.sendWS(ws, serverRes);
|
|
736
|
+
// let endDate = new Date();
|
|
737
|
+
// this.currentPerfomanceMonitor.push({
|
|
738
|
+
// _id: this.idPerformance++,
|
|
739
|
+
// function: 'sendPubDataOnce',
|
|
740
|
+
// publication: subscription.publication,
|
|
741
|
+
// subscriptionData: subscription.subscriptionData,
|
|
742
|
+
// date_start: startDate,
|
|
743
|
+
// date_end: endDate,
|
|
744
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
745
|
+
// result: 'Send ws spec data'
|
|
746
|
+
// });
|
|
571
747
|
resolve(true);
|
|
572
748
|
}, function (err) {
|
|
573
749
|
var serverRes = {
|
|
@@ -591,6 +767,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
591
767
|
var _a;
|
|
592
768
|
var _this = this;
|
|
593
769
|
return __generator(this, function (_b) {
|
|
770
|
+
// let startDate = new Date();
|
|
594
771
|
if (!subscription.clients.length) {
|
|
595
772
|
if (subscription.cacheId) {
|
|
596
773
|
this._nodeCache.del(subscription.cacheId);
|
|
@@ -611,24 +788,45 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
611
788
|
_this._nodeCache.del(subscription.cacheId);
|
|
612
789
|
}
|
|
613
790
|
_this._subscriptions.splice(_this._subscriptions.findIndex(function (a) { return a.publication === subscription.publication && JSON.stringify(a.subscriptionData) === JSON.stringify(subscription.subscriptionData); }), 1);
|
|
791
|
+
// let endDate = new Date();
|
|
792
|
+
// this.currentPerfomanceMonitor.push({
|
|
793
|
+
// _id: this.idPerformance++,
|
|
794
|
+
// function: 'sendPubData',
|
|
795
|
+
// publication: subscription.publication,
|
|
796
|
+
// subscriptionData: subscription.subscriptionData,
|
|
797
|
+
// date_start: startDate,
|
|
798
|
+
// date_end: endDate,
|
|
799
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
800
|
+
// result: 'No clients'
|
|
801
|
+
// });
|
|
614
802
|
resolve(false);
|
|
615
803
|
}
|
|
616
804
|
else {
|
|
617
805
|
if (subscription.cacheId && JSON.stringify(_this._nodeCache.get(subscription.cacheId)) === JSON.stringify(res)) {
|
|
618
806
|
subscription.cacheValid = true;
|
|
807
|
+
// let endDate = new Date();
|
|
808
|
+
// this.currentPerfomanceMonitor.push({
|
|
809
|
+
// _id: this.idPerformance++,
|
|
810
|
+
// function: 'sendPubData',
|
|
811
|
+
// publication: subscription.publication,
|
|
812
|
+
// subscriptionData: subscription.subscriptionData,
|
|
813
|
+
// date_start: startDate,
|
|
814
|
+
// date_end: endDate,
|
|
815
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
816
|
+
// result: 'Same cache dont send'
|
|
817
|
+
// });
|
|
619
818
|
}
|
|
620
819
|
else {
|
|
621
820
|
subscription.clients.forEach(function (client) {
|
|
622
|
-
_this.
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
});
|
|
821
|
+
var ws = _this._mainServer.getWS(client.id_socket);
|
|
822
|
+
if (ws) {
|
|
823
|
+
var serverRes = {
|
|
824
|
+
messageId: client.messageId,
|
|
825
|
+
hasError: false,
|
|
826
|
+
data: res
|
|
827
|
+
};
|
|
828
|
+
_this.sendWS(ws, serverRes);
|
|
829
|
+
}
|
|
632
830
|
});
|
|
633
831
|
var nodeCacheSize = _this._nodeCache.getStats().vsize;
|
|
634
832
|
if (nodeCacheSize > 250000000) {
|
|
@@ -656,12 +854,24 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
656
854
|
subscription.cacheId = cacheId;
|
|
657
855
|
subscription.cacheValid = true;
|
|
658
856
|
}
|
|
857
|
+
// let endDate = new Date();
|
|
858
|
+
// this.currentPerfomanceMonitor.push({
|
|
859
|
+
// _id: this.idPerformance++,
|
|
860
|
+
// function: 'sendPubData',
|
|
861
|
+
// publication: subscription.publication,
|
|
862
|
+
// subscriptionData: subscription.subscriptionData,
|
|
863
|
+
// date_start: startDate,
|
|
864
|
+
// date_end: endDate,
|
|
865
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
866
|
+
// result: 'Same data'
|
|
867
|
+
// });
|
|
659
868
|
}
|
|
660
869
|
resolve(true);
|
|
661
870
|
}
|
|
662
871
|
}, function (err) {
|
|
663
872
|
subscription.clients.forEach(function (client) {
|
|
664
|
-
_this.
|
|
873
|
+
var ws = _this._mainServer.getWS(client.id_socket);
|
|
874
|
+
if (ws) {
|
|
665
875
|
if (ws['id_socket'] === client.id_socket) {
|
|
666
876
|
var serverRes = {
|
|
667
877
|
messageId: client.messageId,
|
|
@@ -670,7 +880,7 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
670
880
|
};
|
|
671
881
|
_this.sendWS(ws, serverRes);
|
|
672
882
|
}
|
|
673
|
-
}
|
|
883
|
+
}
|
|
674
884
|
});
|
|
675
885
|
reject(err);
|
|
676
886
|
});
|