@resolveio/server-lib 9.0.32 → 9.0.34
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/client-server-app.js +7 -48
- package/client-server-app.js.map +1 -1
- package/collections/app-status.collection.js +8 -11
- package/collections/app-status.collection.js.map +1 -1
- package/collections/app-version.collection.js +8 -11
- package/collections/app-version.collection.js.map +1 -1
- package/collections/counter.collection.js +8 -11
- package/collections/counter.collection.js.map +1 -1
- package/collections/cron-job-history.collection.js +9 -12
- package/collections/cron-job-history.collection.js.map +1 -1
- package/collections/cron-job.collection.js +8 -11
- package/collections/cron-job.collection.js.map +1 -1
- package/collections/email-history.collection.js +8 -11
- package/collections/email-history.collection.js.map +1 -1
- package/collections/email-verified.collection.js +9 -12
- package/collections/email-verified.collection.js.map +1 -1
- package/collections/file.collection.js +8 -11
- package/collections/file.collection.js.map +1 -1
- package/collections/flag.collection.js +8 -11
- package/collections/flag.collection.js.map +1 -1
- package/collections/log-method-latency.collection.js +11 -14
- package/collections/log-method-latency.collection.js.map +1 -1
- package/collections/log-subscription.collection.js +13 -16
- package/collections/log-subscription.collection.js.map +1 -1
- package/collections/log.collection.js +16 -19
- package/collections/log.collection.js.map +1 -1
- package/collections/logged-in-users.collection.js +9 -12
- package/collections/logged-in-users.collection.js.map +1 -1
- package/collections/method-call.collection.js +10 -13
- package/collections/method-call.collection.js.map +1 -1
- package/collections/method-response.collection.js +10 -13
- package/collections/method-response.collection.js.map +1 -1
- package/collections/monitor-cpu.collection.js +13 -16
- package/collections/monitor-cpu.collection.js.map +1 -1
- package/collections/monitor-https-inbound.collection.js +13 -16
- package/collections/monitor-https-inbound.collection.js.map +1 -1
- package/collections/monitor-https-outbound.collection.js +15 -18
- package/collections/monitor-https-outbound.collection.js.map +1 -1
- package/collections/monitor-memory.collection.js +12 -15
- package/collections/monitor-memory.collection.js.map +1 -1
- package/collections/monitor-mongo.collection.js +12 -15
- package/collections/monitor-mongo.collection.js.map +1 -1
- package/collections/notification.collection.js +8 -11
- package/collections/notification.collection.js.map +1 -1
- package/collections/queue-flag.collection.js +9 -12
- package/collections/queue-flag.collection.js.map +1 -1
- package/collections/queue-method.collection.js +9 -12
- package/collections/queue-method.collection.js.map +1 -1
- package/collections/queue-response.collection.js +9 -12
- package/collections/queue-response.collection.js.map +1 -1
- package/collections/report-builder-dashboard-builder.collection.js +10 -13
- package/collections/report-builder-dashboard-builder.collection.js.map +1 -1
- package/collections/report-builder-library.collection.js +11 -14
- package/collections/report-builder-library.collection.js.map +1 -1
- package/collections/report-builder-report.collection.js +11 -14
- package/collections/report-builder-report.collection.js.map +1 -1
- package/collections/user-group.collection.js +11 -14
- package/collections/user-group.collection.js.map +1 -1
- package/collections/user-guide.collection.js +8 -11
- package/collections/user-guide.collection.js.map +1 -1
- package/collections/user.collection.js +12 -15
- package/collections/user.collection.js.map +1 -1
- package/cron/cron.js +25 -25
- package/cron/cron.js.map +1 -1
- package/fixtures/cron-jobs.js +30 -80
- package/fixtures/cron-jobs.js.map +1 -1
- package/fixtures/init.js +9 -59
- package/fixtures/init.js.map +1 -1
- package/http/auth.js +344 -460
- package/http/auth.js.map +1 -1
- package/http/health.js +1 -5
- package/http/health.js.map +1 -1
- package/http/home.js +7 -11
- package/http/home.js.map +1 -1
- package/index.js +36 -98
- package/index.js.map +1 -1
- package/managers/cron.manager.js +78 -157
- package/managers/cron.manager.js.map +1 -1
- package/managers/method.manager.js +323 -303
- package/managers/method.manager.js.map +1 -1
- package/managers/mongo.manager.d.ts +14 -14
- package/managers/mongo.manager.js +794 -865
- package/managers/mongo.manager.js.map +1 -1
- package/managers/monitor.manager.js +171 -254
- package/managers/monitor.manager.js.map +1 -1
- package/managers/queue-method.manager.js +69 -166
- package/managers/queue-method.manager.js.map +1 -1
- package/managers/subscription.manager.js +515 -708
- package/managers/subscription.manager.js.map +1 -1
- package/methods/accounts.js +111 -183
- package/methods/accounts.js.map +1 -1
- package/methods/aws.js +156 -262
- package/methods/aws.js.map +1 -1
- package/methods/cloudconvert.js +100 -180
- package/methods/cloudconvert.js.map +1 -1
- package/methods/collections.js +114 -530
- package/methods/collections.js.map +1 -1
- package/methods/counters.js +29 -79
- package/methods/counters.js.map +1 -1
- package/methods/cron-jobs.js +819 -884
- package/methods/cron-jobs.js.map +1 -1
- package/methods/flags.js +1 -5
- package/methods/flags.js.map +1 -1
- package/methods/logs.js +258 -313
- package/methods/logs.js.map +1 -1
- package/methods/monitor.js +289 -348
- package/methods/monitor.js.map +1 -1
- package/methods/pdf.js +341 -340
- package/methods/pdf.js.map +1 -1
- package/methods/report-builder.js +565 -657
- package/methods/report-builder.js.map +1 -1
- package/methods/support.js +67 -185
- package/methods/support.js.map +1 -1
- package/models/app-status.model.js +1 -2
- package/models/app-version.model.js +1 -2
- package/models/billing-logged-in-users.model.js +1 -2
- package/models/collection-document.model.js +1 -2
- package/models/counter.model.js +1 -2
- package/models/cron-job-history.model.js +1 -2
- package/models/cron-job.model.js +1 -2
- package/models/dialog.model.js +1 -2
- package/models/email-history.model.js +1 -2
- package/models/email-verified.model.js +1 -2
- package/models/file.model.js +1 -2
- package/models/flag.model.js +1 -2
- package/models/log-method-latency.model.js +1 -2
- package/models/log-subscription.model.js +1 -2
- package/models/log.model.js +1 -2
- package/models/logged-in-users.model.js +1 -2
- package/models/method-call.model.js +1 -2
- package/models/method-response.model.js +1 -2
- package/models/method.model.js +1 -2
- package/models/monitor-cpu.model.js +1 -2
- package/models/monitor-https-inbound.model.js +1 -2
- package/models/monitor-https-outbound.model.js +1 -2
- package/models/monitor-memory.model.js +1 -2
- package/models/monitor-mongo.model.js +1 -2
- package/models/notification.model.js +1 -2
- package/models/pagination.model.js +2 -5
- package/models/pagination.model.js.map +1 -1
- package/models/permission.model.js +1 -2
- package/models/queue-method.model.js +1 -2
- package/models/queue-response.model.js +1 -2
- package/models/report-builder-dashboard-builder.model.js +1 -2
- package/models/report-builder-library.model.js +1 -2
- package/models/report-builder-report.model.js +1 -2
- package/models/report-builder.model.js +1 -2
- package/models/select-data-label.model.js +1 -2
- package/models/server-response.model.js +1 -2
- package/models/subscription.model.js +1 -2
- package/models/support-ticket.model.js +1 -2
- package/models/user-group.model.js +1 -2
- package/models/user-guide.model.js +1 -2
- package/models/user.model.js +1 -2
- package/package.json +1 -1
- package/public_api.js +70 -82
- package/public_api.js.map +1 -1
- package/publications/app-status.js +4 -8
- package/publications/app-status.js.map +1 -1
- package/publications/app-version.js +4 -8
- package/publications/app-version.js.map +1 -1
- package/publications/cron-jobs.js +9 -13
- package/publications/cron-jobs.js.map +1 -1
- package/publications/files.js +11 -15
- package/publications/files.js.map +1 -1
- package/publications/flags.js +7 -11
- package/publications/flags.js.map +1 -1
- package/publications/logs.js +31 -35
- package/publications/logs.js.map +1 -1
- package/publications/method-calls.js +4 -8
- package/publications/method-calls.js.map +1 -1
- package/publications/method-responses.js +4 -8
- package/publications/method-responses.js.map +1 -1
- package/publications/notifications.js +4 -8
- package/publications/notifications.js.map +1 -1
- package/publications/report-builder-dashboard-builders.js +8 -12
- package/publications/report-builder-dashboard-builders.js.map +1 -1
- package/publications/report-builder-libraries.js +16 -66
- package/publications/report-builder-libraries.js.map +1 -1
- package/publications/report-builder-reports.js +17 -21
- package/publications/report-builder-reports.js.map +1 -1
- package/publications/super-admin.js +3 -7
- package/publications/super-admin.js.map +1 -1
- package/publications/user-groups.js +4 -8
- package/publications/user-groups.js.map +1 -1
- package/publications/user-guides.js +4 -8
- package/publications/user-guides.js.map +1 -1
- package/server-app.js +393 -534
- package/server-app.js.map +1 -1
- package/util/common.js +55 -92
- package/util/common.js.map +1 -1
- package/util/schema-report-builder.js +76 -134
- package/util/schema-report-builder.js.map +1 -1
|
@@ -1,77 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
-
function step(op) {
|
|
16
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
-
while (_) try {
|
|
18
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
-
switch (op[0]) {
|
|
21
|
-
case 0: case 1: t = op; break;
|
|
22
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
-
default:
|
|
26
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
-
if (t[2]) _.ops.pop();
|
|
31
|
-
_.trys.pop(); continue;
|
|
32
|
-
}
|
|
33
|
-
op = body.call(thisArg, _);
|
|
34
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.QueueMethodManager = void 0;
|
|
40
|
-
var queue_flag_collection_1 = require("../collections/queue-flag.collection");
|
|
41
|
-
var queue_method_collection_1 = require("../collections/queue-method.collection");
|
|
42
|
-
var queue_response_collection_1 = require("../collections/queue-response.collection");
|
|
43
|
-
var method_response_collection_1 = require("../collections/method-response.collection");
|
|
44
|
-
var log_collection_1 = require("../collections/log.collection");
|
|
45
|
-
var common_1 = require("../util/common");
|
|
46
|
-
var mongo_manager_1 = require("./mongo.manager");
|
|
47
|
-
var QueueMethodManager = /** @class */ (function () {
|
|
48
|
-
function QueueMethodManager(mainServer) {
|
|
49
|
-
var _this = this;
|
|
1
|
+
import { QueueFlags } from '../collections/queue-flag.collection';
|
|
2
|
+
import { QueueMethods } from '../collections/queue-method.collection';
|
|
3
|
+
import { QueueResponses } from '../collections/queue-response.collection';
|
|
4
|
+
import { MethodResponses } from '../collections/method-response.collection';
|
|
5
|
+
import { Logs } from '../collections/log.collection';
|
|
6
|
+
import { getBinarySize, dateReviver } from '../util/common';
|
|
7
|
+
import { objectIdHexString } from './mongo.manager';
|
|
8
|
+
export class QueueMethodManager {
|
|
9
|
+
constructor(mainServer) {
|
|
50
10
|
this._sendQueue = [];
|
|
51
11
|
this._runningQueue = false;
|
|
52
12
|
this._mainServer = mainServer;
|
|
53
|
-
setInterval(
|
|
54
|
-
if (!
|
|
55
|
-
if (
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
13
|
+
setInterval(() => {
|
|
14
|
+
if (!this._runningQueue) {
|
|
15
|
+
if (this._sendQueue.length) {
|
|
16
|
+
this._runningQueue = true;
|
|
17
|
+
for (let i = this._sendQueue.length - 1; i >= 0; i--) {
|
|
18
|
+
let ws = this._mainServer.getWS(this._sendQueue[i].id_ws);
|
|
59
19
|
if (ws && ws.readyState === ws.OPEN) {
|
|
60
20
|
if (ws.bufferedAmount < 20480) {
|
|
61
|
-
|
|
62
|
-
ws.send(JSON.stringify(sendItem.response),
|
|
21
|
+
let sendItem = this._sendQueue.pop();
|
|
22
|
+
ws.send(JSON.stringify(sendItem.response), (error) => {
|
|
63
23
|
if (error) {
|
|
64
24
|
console.log('Error on WS: ', error);
|
|
65
|
-
|
|
25
|
+
this._mainServer.unsubscribeWS(ws);
|
|
66
26
|
}
|
|
67
27
|
});
|
|
68
28
|
if (sendItem.method !== 'reportBuilderGetResults' && sendItem.method !== 'reportBuilderGetDistinctValue' && sendItem.method !== 'reportBuilderBuildTree' && sendItem.method !== 'generatePDF' && sendItem.method !== 'getWOOfflineData' && sendItem.method !== 'countQuery' && sendItem.method !== 'countWithQuery' && sendItem.method !== 'countCollectionWithQuery' && sendItem.method !== 'find' && sendItem.method !== 'findOne' && sendItem.method !== 'findWithOptions' && sendItem.method !== 'setWSAppVersion' && sendItem.method !== 'uploadFileAndSave' && sendItem.method !== 'getDrivers') {
|
|
69
|
-
|
|
70
|
-
_id:
|
|
29
|
+
Logs.create({
|
|
30
|
+
_id: objectIdHexString(),
|
|
71
31
|
type: 'client-response',
|
|
72
32
|
collection: '',
|
|
73
33
|
id_document: '',
|
|
74
|
-
payload:
|
|
34
|
+
payload: getBinarySize(JSON.stringify([sendItem.methodData, sendItem.response])) < 200000 ? JSON.stringify([sendItem.methodData, sendItem.response], null, 2) : 'Too Big',
|
|
75
35
|
method: sendItem.method,
|
|
76
36
|
id_user: ws['id_user'],
|
|
77
37
|
user: ws['user'],
|
|
@@ -79,30 +39,27 @@ var QueueMethodManager = /** @class */ (function () {
|
|
|
79
39
|
route: ''
|
|
80
40
|
});
|
|
81
41
|
}
|
|
82
|
-
|
|
83
|
-
_id:
|
|
42
|
+
MethodResponses.create({
|
|
43
|
+
_id: objectIdHexString(),
|
|
84
44
|
__v: 0,
|
|
85
45
|
id_user: sendItem.id_user,
|
|
86
46
|
message_id: sendItem.messageId,
|
|
87
|
-
response:
|
|
47
|
+
response: getBinarySize(JSON.stringify(sendItem.response)) < 200000 ? sendItem.response : 'Too Big',
|
|
88
48
|
method: sendItem.method,
|
|
89
49
|
date: sendItem.date
|
|
90
50
|
});
|
|
91
51
|
}
|
|
92
52
|
}
|
|
93
|
-
};
|
|
94
|
-
for (var i = _this._sendQueue.length - 1; i >= 0; i--) {
|
|
95
|
-
_loop_1(i);
|
|
96
53
|
}
|
|
97
|
-
|
|
54
|
+
this._runningQueue = false;
|
|
98
55
|
}
|
|
99
56
|
}
|
|
100
57
|
}, 10);
|
|
101
58
|
}
|
|
102
|
-
|
|
59
|
+
addMethodToQueue(id_methodLatency, id_ws, id_user, user, messageDate, messageId, method, data) {
|
|
103
60
|
// console.log('Add Method To Queue', method);
|
|
104
|
-
|
|
105
|
-
_id:
|
|
61
|
+
QueueMethods.create({
|
|
62
|
+
_id: objectIdHexString(),
|
|
106
63
|
__v: 0,
|
|
107
64
|
id_ws: id_ws,
|
|
108
65
|
messageId: messageId,
|
|
@@ -114,72 +71,32 @@ var QueueMethodManager = /** @class */ (function () {
|
|
|
114
71
|
date: messageDate,
|
|
115
72
|
id_methodLatency: id_methodLatency
|
|
116
73
|
});
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
queue_flag_collection_1.QueueFlags.insertOne({ _id: 'method-queue', __v: 0 }).then(function (res) { return __awaiter(_this, void 0, void 0, function () {
|
|
137
|
-
var updates, i, update;
|
|
138
|
-
return __generator(this, function (_a) {
|
|
139
|
-
switch (_a.label) {
|
|
140
|
-
case 0:
|
|
141
|
-
if (!res) return [3 /*break*/, 8];
|
|
142
|
-
return [4 /*yield*/, queue_method_collection_1.QueueMethods.find({}, { sort: { createdAt: 1 } })];
|
|
143
|
-
case 1:
|
|
144
|
-
updates = _a.sent();
|
|
145
|
-
i = 0;
|
|
146
|
-
_a.label = 2;
|
|
147
|
-
case 2:
|
|
148
|
-
if (!(i < updates.length)) return [3 /*break*/, 6];
|
|
149
|
-
update = updates[i];
|
|
150
|
-
update.method_data = JSON.parse(update.method_data_string, common_1.dateReviver);
|
|
151
|
-
return [4 /*yield*/, this._mainServer.getMethodManager().callMethodQueue(update)];
|
|
152
|
-
case 3:
|
|
153
|
-
_a.sent();
|
|
154
|
-
return [4 /*yield*/, queue_method_collection_1.QueueMethods.deleteOne({ _id: update._id })];
|
|
155
|
-
case 4:
|
|
156
|
-
_a.sent();
|
|
157
|
-
_a.label = 5;
|
|
158
|
-
case 5:
|
|
159
|
-
i++;
|
|
160
|
-
return [3 /*break*/, 2];
|
|
161
|
-
case 6:
|
|
162
|
-
queue_flag_collection_1.QueueFlags.deleteOne({ _id: 'method-queue' });
|
|
163
|
-
return [4 /*yield*/, queue_method_collection_1.QueueMethods.countDocuments()];
|
|
164
|
-
case 7:
|
|
165
|
-
updateCnt = _a.sent();
|
|
166
|
-
if (updateCnt) {
|
|
167
|
-
this.runMethodQueue(updateCnt);
|
|
168
|
-
}
|
|
169
|
-
_a.label = 8;
|
|
170
|
-
case 8: return [2 /*return*/];
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
}); }, function () { });
|
|
174
|
-
}
|
|
175
|
-
return [2 /*return*/];
|
|
74
|
+
}
|
|
75
|
+
async runMethodQueue(count) {
|
|
76
|
+
let updateCnt = count ? count : await QueueMethods.countDocuments();
|
|
77
|
+
if (updateCnt) {
|
|
78
|
+
// console.log('Run Method Queue', updateCnt);
|
|
79
|
+
QueueFlags.insertOne({ _id: 'method-queue', __v: 0 }).then(async (res) => {
|
|
80
|
+
if (res) {
|
|
81
|
+
let updates = await QueueMethods.find({}, { sort: { createdAt: 1 } });
|
|
82
|
+
for (let i = 0; i < updates.length; i++) {
|
|
83
|
+
let update = updates[i];
|
|
84
|
+
update.method_data = JSON.parse(update.method_data_string, dateReviver);
|
|
85
|
+
await this._mainServer.getMethodManager().callMethodQueue(update);
|
|
86
|
+
await QueueMethods.deleteOne({ _id: update._id });
|
|
87
|
+
}
|
|
88
|
+
QueueFlags.deleteOne({ _id: 'method-queue' });
|
|
89
|
+
updateCnt = await QueueMethods.countDocuments();
|
|
90
|
+
if (updateCnt) {
|
|
91
|
+
this.runMethodQueue(updateCnt);
|
|
92
|
+
}
|
|
176
93
|
}
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
_id:
|
|
94
|
+
}, () => { });
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
addMethodResponse(update, response) {
|
|
98
|
+
QueueResponses.create({
|
|
99
|
+
_id: objectIdHexString(),
|
|
183
100
|
__v: 0,
|
|
184
101
|
id_ws: update.id_ws,
|
|
185
102
|
id_user: update.id_user,
|
|
@@ -189,35 +106,21 @@ var QueueMethodManager = /** @class */ (function () {
|
|
|
189
106
|
method: update.method,
|
|
190
107
|
date: update.date
|
|
191
108
|
});
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
response = responses[i];
|
|
209
|
-
this._sendQueue.splice(0, 0, response);
|
|
210
|
-
queue_response_collection_1.QueueResponses.deleteOne({ _id: response._id });
|
|
211
|
-
}
|
|
212
|
-
this._runningMethodResponse = false;
|
|
213
|
-
_a.label = 3;
|
|
214
|
-
case 3: return [2 /*return*/];
|
|
215
|
-
}
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
|
-
};
|
|
219
|
-
return QueueMethodManager;
|
|
220
|
-
}());
|
|
221
|
-
exports.QueueMethodManager = QueueMethodManager;
|
|
109
|
+
}
|
|
110
|
+
async runMethodResponse() {
|
|
111
|
+
let responseCnt = await QueueResponses.countDocuments();
|
|
112
|
+
if (responseCnt && !this._runningMethodResponse) {
|
|
113
|
+
this._runningMethodResponse = true;
|
|
114
|
+
let wsList = this._mainServer.getWSList();
|
|
115
|
+
let responses = await QueueResponses.find({ id_ws: { $in: wsList } });
|
|
116
|
+
for (let i = 0; i < responses.length; i++) {
|
|
117
|
+
let response = responses[i];
|
|
118
|
+
this._sendQueue.splice(0, 0, response);
|
|
119
|
+
QueueResponses.deleteOne({ _id: response._id });
|
|
120
|
+
}
|
|
121
|
+
this._runningMethodResponse = false;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
222
125
|
|
|
223
126
|
//# sourceMappingURL=queue-method.manager.js.map
|
|
@@ -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,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C,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 !== 'reportBuilderGetResults' && sendItem.method !== 'reportBuilderGetDistinctValue' && sendItem.method !== 'reportBuilderBuildTree' && sendItem.method !== 'generatePDF' && sendItem.method !== 'getWOOfflineData' && sendItem.method !== 'countQuery' && sendItem.method !== 'countWithQuery' && sendItem.method !== 'countCollectionWithQuery' && sendItem.method !== 'find' && sendItem.method !== 'findOne' && sendItem.method !== 'findWithOptions' && sendItem.method !== 'setWSAppVersion' && sendItem.method !== 'uploadFileAndSave' && sendItem.method !== 'getDrivers') {\n\t\t\t\t\t\t\t\t\tLogs.create({\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 : '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}"]}
|
|
1
|
+
{"version":3,"sources":["../../src/managers/queue-method.manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sCAAsC,CAAC;AAElE,OAAO,EAAE,YAAY,EAAE,MAAM,wCAAwC,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,0CAA0C,CAAC;AAE1E,OAAO,EAAE,eAAe,EAAE,MAAM,2CAA2C,CAAC;AAC5E,OAAO,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AACrD,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE5D,OAAO,EA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ACJ,CAAC;IAEM,KAAK,CAAC,iBAAiB;QAC7B,IAAI,WAAW,GAAG,MAAM,cAAc,CAAC,cAAc,EAAE,CAAC;QAExD,IAAI,WAAW,IAAI,CAAC,IAAI,CAAC,sBAAsB,EAAE;YAChD,IAAI,CAAC,sBAAsB,GAAG,IAAI,CAAC;YAEnC,IAAI,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,SAAS,EAAE,CAAC;YAE1C,IAAI,SAAS,GAAG,MAAM,cAAc,CAAC,IAAI,CAAC,EAAC,KAAK,EAAE,EAAC,GAAG,EAAE,MAAM,EAAC,EAAC,CAAC,CAAC;YAElE,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;gBAC1C,IAAI,QAAQ,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC;gBAE5B,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC;gBAEvC,cAAc,CAAC,SAAS,CAAC,EAAC,GAAG,EAAE,QAAQ,CAAC,GAAG,EAAC,CAAC,CAAC;aAC9C;YAED,IAAI,CAAC,sBAAsB,GAAG,KAAK,CAAC;SACpC;IACF,CAAC;CACD","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 !== 'reportBuilderGetResults' && sendItem.method !== 'reportBuilderGetDistinctValue' && sendItem.method !== 'reportBuilderBuildTree' && sendItem.method !== 'generatePDF' && sendItem.method !== 'getWOOfflineData' && sendItem.method !== 'countQuery' && sendItem.method !== 'countWithQuery' && sendItem.method !== 'countCollectionWithQuery' && sendItem.method !== 'find' && sendItem.method !== 'findOne' && sendItem.method !== 'findWithOptions' && sendItem.method !== 'setWSAppVersion' && sendItem.method !== 'uploadFileAndSave' && sendItem.method !== 'getDrivers') {\n\t\t\t\t\t\t\t\t\tLogs.create({\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 : '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}"]}
|