@resolveio/server-lib 9.1.44 → 9.2.1
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/fixtures/cron-jobs.js +0 -13
- package/fixtures/cron-jobs.js.map +1 -1
- package/fixtures/init.js +12 -0
- package/fixtures/init.js.map +1 -1
- package/managers/method.manager.d.ts +0 -2
- package/managers/method.manager.js +0 -114
- package/managers/method.manager.js.map +1 -1
- package/managers/subscription.manager.js +20 -55
- package/managers/subscription.manager.js.map +1 -1
- package/methods/accounts.js +27 -57
- package/methods/accounts.js.map +1 -1
- package/methods/aws.js +0 -11
- package/methods/aws.js.map +1 -1
- package/methods/cloudconvert.js +0 -2
- package/methods/cloudconvert.js.map +1 -1
- package/methods/collections.js +0 -5
- package/methods/collections.js.map +1 -1
- package/methods/counters.js +0 -3
- package/methods/counters.js.map +1 -1
- package/methods/cron-jobs.js +0 -23
- package/methods/cron-jobs.js.map +1 -1
- package/methods/logs.js +0 -4
- package/methods/logs.js.map +1 -1
- package/methods/monitor.js +0 -1
- package/methods/monitor.js.map +1 -1
- package/methods/pdf.js +0 -6
- package/methods/pdf.js.map +1 -1
- package/methods/report-builder.js +0 -3
- package/methods/report-builder.js.map +1 -1
- package/models/method.model.d.ts +0 -1
- package/models/method.model.js.map +1 -1
- package/models/subscription.model.d.ts +0 -2
- package/models/subscription.model.js.map +1 -1
- package/package.json +1 -1
- package/public_api.d.ts +0 -5
- package/public_api.js +0 -5
- package/public_api.js.map +1 -1
- package/publications/cron-jobs.js +1 -4
- package/publications/cron-jobs.js.map +1 -1
- package/publications/files.js +2 -8
- package/publications/files.js.map +1 -1
- package/publications/flags.js +1 -4
- package/publications/flags.js.map +1 -1
- package/publications/logs.js +6 -24
- package/publications/logs.js.map +1 -1
- package/publications/report-builder-reports.js +3 -12
- package/publications/report-builder-reports.js.map +1 -1
- package/server-app.d.ts +0 -3
- package/server-app.js +0 -14
- package/server-app.js.map +1 -1
- package/collections/queue-flag.collection.d.ts +0 -3
- package/collections/queue-flag.collection.js +0 -39
- package/collections/queue-flag.collection.js.map +0 -1
- package/collections/queue-method.collection.d.ts +0 -3
- package/collections/queue-method.collection.js +0 -70
- package/collections/queue-method.collection.js.map +0 -1
- package/collections/queue-response.collection.d.ts +0 -3
- package/collections/queue-response.collection.js +0 -61
- package/collections/queue-response.collection.js.map +0 -1
- package/managers/queue-method.manager.d.ts +0 -13
- package/managers/queue-method.manager.js +0 -223
- package/managers/queue-method.manager.js.map +0 -1
- package/models/queue-method.model.d.ts +0 -12
- package/models/queue-method.model.js +0 -4
- package/models/queue-method.model.js.map +0 -1
- package/models/queue-response.model.d.ts +0 -10
- package/models/queue-response.model.js +0 -4
- package/models/queue-response.model.js.map +0 -1
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.QueueResponses = void 0;
|
|
4
|
-
var index_1 = require("../index");
|
|
5
|
-
var mongo_manager_1 = require("../managers/mongo.manager");
|
|
6
|
-
var schema = {
|
|
7
|
-
_id: {
|
|
8
|
-
type: String,
|
|
9
|
-
optional: true
|
|
10
|
-
},
|
|
11
|
-
__v: {
|
|
12
|
-
type: Number,
|
|
13
|
-
optional: true
|
|
14
|
-
},
|
|
15
|
-
updatedAt: {
|
|
16
|
-
type: Date,
|
|
17
|
-
optional: true
|
|
18
|
-
},
|
|
19
|
-
createdAt: {
|
|
20
|
-
type: Date,
|
|
21
|
-
optional: true
|
|
22
|
-
},
|
|
23
|
-
method: {
|
|
24
|
-
type: String
|
|
25
|
-
},
|
|
26
|
-
id_ws: {
|
|
27
|
-
type: String
|
|
28
|
-
},
|
|
29
|
-
messageId: {
|
|
30
|
-
type: Number
|
|
31
|
-
},
|
|
32
|
-
id_user: {
|
|
33
|
-
type: String
|
|
34
|
-
},
|
|
35
|
-
user: {
|
|
36
|
-
type: String
|
|
37
|
-
},
|
|
38
|
-
response: {
|
|
39
|
-
type: Object,
|
|
40
|
-
blackbox: true
|
|
41
|
-
},
|
|
42
|
-
date: {
|
|
43
|
-
type: Date
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
exports.QueueResponses = null;
|
|
47
|
-
initializeCollection();
|
|
48
|
-
function initializeCollection() {
|
|
49
|
-
if (index_1.ResolveIOServer && index_1.ResolveIOServer.getMainDB()) {
|
|
50
|
-
var model = new mongo_manager_1.Model('queue-responses', schema, false, false, [], true, false);
|
|
51
|
-
exports.QueueResponses = model.collection_main;
|
|
52
|
-
exports.QueueResponses.createIndex({ date: 1 }, { expireAfterSeconds: 60 });
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
55
|
-
setTimeout(function () {
|
|
56
|
-
initializeCollection();
|
|
57
|
-
}, 1);
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
//# sourceMappingURL=queue-response.collection.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/collections/queue-response.collection.ts"],"names":[],"mappings":";;;AAAA,kCAA2C;AAC3C,2DAA8D;AAG9D,IAAI,MAAM,GAAQ;IACjB,GAAG,EAAE;QACJ,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACd;IACD,GAAG,EAAE;QACJ,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACd;IACD,SAAS,EAAE;QACV,IAAI,EAAE,IAAI;QACV,QAAQ,EAAE,IAAI;KACd;IACD,SAAS,EAAE;QACV,IAAI,EAAE,IAAI;QACV,QAAQ,EAAE,IAAI;KACd;IACD,MAAM,EAAE;QACP,IAAI,EAAE,MAAM;KACZ;IACD,KAAK,EAAE;QACN,IAAI,EAAE,MAAM;KACZ;IACD,SAAS,EAAE;QACV,IAAI,EAAE,MAAM;KACZ;IACD,OAAO,EAAE;QACR,IAAI,EAAE,MAAM;KACZ;IACD,IAAI,EAAE;QACL,IAAI,EAAE,MAAM;KACZ;IACD,QAAQ,EAAE;QACT,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;KACd;IACD,IAAI,EAAE;QACL,IAAI,EAAE,IAAI;KACV;CACD,CAAC;AAES,QAAA,cAAc,GAAmC,IAAI,CAAC;AAEjE,oBAAoB,EAAE,CAAC;AAEvB,SAAS,oBAAoB;IAC5B,IAAI,uBAAe,IAAI,uBAAe,CAAC,SAAS,EAAE,EAAE;QACnD,IAAM,KAAK,GAAG,IAAI,qBAAK,CAAqB,iBAAiB,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC;QACtG,sBAAc,GAAG,KAAK,CAAC,eAAe,CAAC;QACvC,sBAAc,CAAC,WAAW,CAAC,EAAC,IAAI,EAAE,CAAC,EAAC,EAAE,EAAC,kBAAkB,EAAE,EAAE,EAAC,CAAC,CAAC;KAChE;SACI;QACJ,UAAU,CAAC;YACV,oBAAoB,EAAE,CAAC;QACxB,CAAC,EAAE,CAAC,CAAC,CAAC;KACN;AACF,CAAC","file":"queue-response.collection.js","sourcesContent":["import { ResolveIOServer } from '../index';\nimport { Collection, Model } from '../managers/mongo.manager';\nimport { QueueResponseModel } from '../models/queue-response.model';\n\nlet schema: any = {\n\t_id: {\n\t\ttype: String,\n\t\toptional: true\n\t},\n\t__v: {\n\t\ttype: Number,\n\t\toptional: true \n\t},\n\tupdatedAt: {\n\t\ttype: Date,\n\t\toptional: true\n\t},\n\tcreatedAt: {\n\t\ttype: Date,\n\t\toptional: true\n\t},\n\tmethod: {\n\t\ttype: String\n\t},\n\tid_ws: {\n\t\ttype: String\n\t},\n\tmessageId: {\n\t\ttype: Number\n\t},\n\tid_user: {\n\t\ttype: String\n\t},\n\tuser: {\n\t\ttype: String\n\t},\n\tresponse: {\n\t\ttype: Object,\n\t\tblackbox: true\n\t},\n\tdate: {\n\t\ttype: Date\n\t}\n};\n\nexport let QueueResponses: Collection<QueueResponseModel> = null;\n\ninitializeCollection();\n\nfunction initializeCollection() {\n\tif (ResolveIOServer && ResolveIOServer.getMainDB()) {\n\t\tconst model = new Model<QueueResponseModel>('queue-responses', schema, false, false, [], true, false);\n\t\tQueueResponses = model.collection_main;\n\t\tQueueResponses.createIndex({date: 1}, {expireAfterSeconds: 60});\n\t}\n\telse {\n\t\tsetTimeout(() => {\n\t\t\tinitializeCollection();\n\t\t}, 1);\n\t}\n}"]}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { QueueMethodModel } from '../models/queue-method.model';
|
|
2
|
-
import { ServerResponseModel } from '../models/server-response.model';
|
|
3
|
-
export declare class QueueMethodManager {
|
|
4
|
-
private _mainServer;
|
|
5
|
-
private _sendQueue;
|
|
6
|
-
private _runningQueue;
|
|
7
|
-
private _runningMethodResponse;
|
|
8
|
-
constructor(mainServer: any);
|
|
9
|
-
addMethodToQueue(id_methodLatency: string, id_ws: string, id_user: string, user: string, messageDate: Date, messageId: number, method: string, data: any[]): void;
|
|
10
|
-
runMethodQueue(count?: number): Promise<void>;
|
|
11
|
-
addMethodResponse(update: QueueMethodModel, response: ServerResponseModel): void;
|
|
12
|
-
runMethodResponse(): Promise<void>;
|
|
13
|
-
}
|
|
@@ -1,223 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
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;
|
|
50
|
-
this._sendQueue = [];
|
|
51
|
-
this._runningQueue = false;
|
|
52
|
-
this._mainServer = mainServer;
|
|
53
|
-
setInterval(function () {
|
|
54
|
-
if (!_this._runningQueue) {
|
|
55
|
-
if (_this._sendQueue.length) {
|
|
56
|
-
_this._runningQueue = true;
|
|
57
|
-
var _loop_1 = function (i) {
|
|
58
|
-
var ws = _this._mainServer.getWS(_this._sendQueue[i].id_ws);
|
|
59
|
-
if (ws && ws.readyState === ws.OPEN) {
|
|
60
|
-
if (ws.bufferedAmount < 20480) {
|
|
61
|
-
var sendItem = _this._sendQueue.pop();
|
|
62
|
-
ws.send(JSON.stringify(sendItem.response), function (error) {
|
|
63
|
-
if (error) {
|
|
64
|
-
console.log('Error on WS: ', error);
|
|
65
|
-
_this._mainServer.unsubscribeWS(ws);
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
if (sendItem.method !== 'getWOOfflineData' && sendItem.method !== 'getDrivers') {
|
|
69
|
-
log_collection_1.Logs.insertOne({
|
|
70
|
-
_id: mongo_manager_1.objectIdHexString(),
|
|
71
|
-
type: 'client-response',
|
|
72
|
-
collection: '',
|
|
73
|
-
id_document: '',
|
|
74
|
-
payload: common_1.getBinarySize(JSON.stringify([sendItem.methodData, sendItem.response])) < 200000 ? JSON.stringify([sendItem.methodData, sendItem.response], null, 2) : 'Too Big',
|
|
75
|
-
method: sendItem.method,
|
|
76
|
-
id_user: ws['id_user'] || '',
|
|
77
|
-
user: ws['user'] || '',
|
|
78
|
-
messageId: sendItem.messageId,
|
|
79
|
-
route: ''
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
method_response_collection_1.MethodResponses.create({
|
|
83
|
-
_id: mongo_manager_1.objectIdHexString(),
|
|
84
|
-
__v: 0,
|
|
85
|
-
id_user: sendItem.id_user,
|
|
86
|
-
message_id: sendItem.messageId,
|
|
87
|
-
response: common_1.getBinarySize(JSON.stringify(sendItem.response)) < 200000 ? sendItem.response : { error: 'Too Big' },
|
|
88
|
-
method: sendItem.method,
|
|
89
|
-
date: sendItem.date
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
};
|
|
94
|
-
for (var i = _this._sendQueue.length - 1; i >= 0; i--) {
|
|
95
|
-
_loop_1(i);
|
|
96
|
-
}
|
|
97
|
-
_this._runningQueue = false;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}, 10);
|
|
101
|
-
}
|
|
102
|
-
QueueMethodManager.prototype.addMethodToQueue = function (id_methodLatency, id_ws, id_user, user, messageDate, messageId, method, data) {
|
|
103
|
-
// console.log('Add Method To Queue', method);
|
|
104
|
-
queue_method_collection_1.QueueMethods.create({
|
|
105
|
-
_id: mongo_manager_1.objectIdHexString(),
|
|
106
|
-
__v: 0,
|
|
107
|
-
id_ws: id_ws,
|
|
108
|
-
messageId: messageId,
|
|
109
|
-
method: method,
|
|
110
|
-
method_data: [],
|
|
111
|
-
method_data_string: JSON.stringify(data),
|
|
112
|
-
id_user: id_user,
|
|
113
|
-
user: user,
|
|
114
|
-
date: messageDate,
|
|
115
|
-
id_methodLatency: id_methodLatency
|
|
116
|
-
});
|
|
117
|
-
};
|
|
118
|
-
QueueMethodManager.prototype.runMethodQueue = function (count) {
|
|
119
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
120
|
-
var updateCnt, _a;
|
|
121
|
-
var _this = this;
|
|
122
|
-
return __generator(this, function (_b) {
|
|
123
|
-
switch (_b.label) {
|
|
124
|
-
case 0:
|
|
125
|
-
if (!count) return [3 /*break*/, 1];
|
|
126
|
-
_a = count;
|
|
127
|
-
return [3 /*break*/, 3];
|
|
128
|
-
case 1: return [4 /*yield*/, queue_method_collection_1.QueueMethods.countDocuments()];
|
|
129
|
-
case 2:
|
|
130
|
-
_a = _b.sent();
|
|
131
|
-
_b.label = 3;
|
|
132
|
-
case 3:
|
|
133
|
-
updateCnt = _a;
|
|
134
|
-
if (updateCnt) {
|
|
135
|
-
// console.log('Run Method Queue', updateCnt);
|
|
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*/];
|
|
176
|
-
}
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
};
|
|
180
|
-
QueueMethodManager.prototype.addMethodResponse = function (update, response) {
|
|
181
|
-
queue_response_collection_1.QueueResponses.create({
|
|
182
|
-
_id: mongo_manager_1.objectIdHexString(),
|
|
183
|
-
__v: 0,
|
|
184
|
-
id_ws: update.id_ws,
|
|
185
|
-
id_user: update.id_user,
|
|
186
|
-
user: update.user,
|
|
187
|
-
messageId: update.messageId,
|
|
188
|
-
response: response,
|
|
189
|
-
method: update.method,
|
|
190
|
-
date: update.date
|
|
191
|
-
});
|
|
192
|
-
};
|
|
193
|
-
QueueMethodManager.prototype.runMethodResponse = function () {
|
|
194
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
195
|
-
var responseCnt, wsList, responses, i, response;
|
|
196
|
-
return __generator(this, function (_a) {
|
|
197
|
-
switch (_a.label) {
|
|
198
|
-
case 0: return [4 /*yield*/, queue_response_collection_1.QueueResponses.countDocuments()];
|
|
199
|
-
case 1:
|
|
200
|
-
responseCnt = _a.sent();
|
|
201
|
-
if (!(responseCnt && !this._runningMethodResponse)) return [3 /*break*/, 3];
|
|
202
|
-
this._runningMethodResponse = true;
|
|
203
|
-
wsList = this._mainServer.getWSList();
|
|
204
|
-
return [4 /*yield*/, queue_response_collection_1.QueueResponses.find({ id_ws: { $in: wsList } })];
|
|
205
|
-
case 2:
|
|
206
|
-
responses = _a.sent();
|
|
207
|
-
for (i = 0; i < responses.length; i++) {
|
|
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;
|
|
222
|
-
|
|
223
|
-
//# sourceMappingURL=queue-method.manager.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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,IAA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":["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}"]}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { CollectionDocument } from './collection-document.model';
|
|
2
|
-
export interface QueueMethodModel extends CollectionDocument {
|
|
3
|
-
method: string;
|
|
4
|
-
method_data: any[];
|
|
5
|
-
method_data_string: string;
|
|
6
|
-
id_ws: string;
|
|
7
|
-
messageId: number;
|
|
8
|
-
id_user: string;
|
|
9
|
-
user: string;
|
|
10
|
-
date: Date;
|
|
11
|
-
id_methodLatency: string;
|
|
12
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/models/queue-method.model.ts"],"names":[],"mappings":"","file":"queue-method.model.js","sourcesContent":["import { CollectionDocument } from './collection-document.model';\n\nexport interface QueueMethodModel extends CollectionDocument {\n\tmethod: string;\n\tmethod_data: any[];\n\tmethod_data_string: string;\n\tid_ws: string;\n\tmessageId: number;\n\tid_user: string;\n\tuser: string;\n\tdate: Date;\n\tid_methodLatency: string;\n}"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/models/queue-response.model.ts"],"names":[],"mappings":"","file":"queue-response.model.js","sourcesContent":["import { CollectionDocument } from './collection-document.model';\n\nexport interface QueueResponseModel extends CollectionDocument {\n\tmethod: string;\n\tid_ws: string;\n\tmessageId: number;\n\tid_user: string;\n\tuser: string;\n\tresponse: any;\n\tdate: Date;\n}"]}
|