@resolveio/server-lib 22.0.2 → 22.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/managers/method.manager.d.ts +12 -0
- package/managers/method.manager.js +144 -21
- package/managers/method.manager.js.map +1 -1
- package/managers/subscription.manager.js +44 -5
- package/managers/subscription.manager.js.map +1 -1
- package/managers/worker-server.manager.js +32 -17
- package/managers/worker-server.manager.js.map +1 -1
- package/package.json +1 -1
|
@@ -33,6 +33,9 @@ export declare class MethodManager {
|
|
|
33
33
|
private _debugCallMethodCronJobHits;
|
|
34
34
|
private _debugSendQueueHits;
|
|
35
35
|
private _enableDebug;
|
|
36
|
+
private _ready;
|
|
37
|
+
private _readyEmitter;
|
|
38
|
+
private _readyError;
|
|
36
39
|
private _localActiveCounts;
|
|
37
40
|
private _localWaitQueues;
|
|
38
41
|
clientDir: string;
|
|
@@ -40,6 +43,15 @@ export declare class MethodManager {
|
|
|
40
43
|
constructor();
|
|
41
44
|
static create(websocketManager: WebSocketManager, monitorManagerFunction: MonitorManagerFunction, isWorkersEnabled: any, isWorkerInstance: any): MethodManager;
|
|
42
45
|
private initialize;
|
|
46
|
+
private markReady;
|
|
47
|
+
private markReadyFailure;
|
|
48
|
+
onReady(callback: () => void): () => void;
|
|
49
|
+
private waitForReadyEvent;
|
|
50
|
+
private waitForReadyError;
|
|
51
|
+
private waitForReadyTimeout;
|
|
52
|
+
isReady(): boolean;
|
|
53
|
+
getReadyError(): any;
|
|
54
|
+
waitUntilReady(timeoutMs?: number): Promise<void>;
|
|
43
55
|
getMethod(methodName: string): MethodAllModel;
|
|
44
56
|
methods(method: MethodModel): void;
|
|
45
57
|
private reportMethodError;
|
|
@@ -86,9 +86,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
86
86
|
exports.MethodManager = exports.AWS = void 0;
|
|
87
87
|
var client_s3_1 = require("@aws-sdk/client-s3");
|
|
88
88
|
var client_sesv2_1 = require("@aws-sdk/client-sesv2");
|
|
89
|
+
var events_1 = require("events");
|
|
89
90
|
var fs = require("fs");
|
|
90
91
|
var nodemailer = require("nodemailer");
|
|
91
92
|
var path = require("path");
|
|
93
|
+
var promises_1 = require("timers/promises");
|
|
92
94
|
var email_history_collection_1 = require("../collections/email-history.collection");
|
|
93
95
|
var flag_collection_1 = require("../collections/flag.collection");
|
|
94
96
|
var log_collection_1 = require("../collections/log.collection");
|
|
@@ -290,6 +292,9 @@ var MethodManager = /** @class */ (function () {
|
|
|
290
292
|
this._debugCallMethodCronJobHits = 0;
|
|
291
293
|
this._debugSendQueueHits = 0;
|
|
292
294
|
this._enableDebug = false;
|
|
295
|
+
this._ready = false;
|
|
296
|
+
this._readyEmitter = new events_1.EventEmitter();
|
|
297
|
+
this._readyError = null;
|
|
293
298
|
this._localActiveCounts = new Map();
|
|
294
299
|
this._localWaitQueues = new Map();
|
|
295
300
|
this.clientDir = '';
|
|
@@ -327,12 +332,13 @@ var MethodManager = /** @class */ (function () {
|
|
|
327
332
|
}
|
|
328
333
|
}
|
|
329
334
|
setImmediate(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
330
|
-
var flag;
|
|
335
|
+
var flag, error_2;
|
|
331
336
|
return __generator(this, function (_a) {
|
|
332
337
|
switch (_a.label) {
|
|
333
|
-
case 0:
|
|
334
|
-
|
|
335
|
-
|
|
338
|
+
case 0:
|
|
339
|
+
_a.trys.push([0, 4, , 5]);
|
|
340
|
+
// Methods
|
|
341
|
+
return [4 /*yield*/, (0, cron_jobs_1.loadServerCronJobs)()];
|
|
336
342
|
case 1:
|
|
337
343
|
// Methods
|
|
338
344
|
_a.sent();
|
|
@@ -363,7 +369,14 @@ var MethodManager = /** @class */ (function () {
|
|
|
363
369
|
return [4 /*yield*/, this.loadPendingEmails()];
|
|
364
370
|
case 3:
|
|
365
371
|
_a.sent();
|
|
366
|
-
|
|
372
|
+
this.markReady();
|
|
373
|
+
return [3 /*break*/, 5];
|
|
374
|
+
case 4:
|
|
375
|
+
error_2 = _a.sent();
|
|
376
|
+
console.error(new Date(), 'Method Manager init failed', error_2);
|
|
377
|
+
this.markReadyFailure(error_2);
|
|
378
|
+
return [3 /*break*/, 5];
|
|
379
|
+
case 5: return [2 /*return*/];
|
|
367
380
|
}
|
|
368
381
|
});
|
|
369
382
|
}); });
|
|
@@ -423,6 +436,116 @@ var MethodManager = /** @class */ (function () {
|
|
|
423
436
|
this.setupEmailWatcher();
|
|
424
437
|
}
|
|
425
438
|
};
|
|
439
|
+
MethodManager.prototype.markReady = function () {
|
|
440
|
+
if (this._ready) {
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
this._ready = true;
|
|
444
|
+
this._readyEmitter.emit('ready');
|
|
445
|
+
this._readyEmitter.removeAllListeners('ready');
|
|
446
|
+
this._readyEmitter.removeAllListeners('readyError');
|
|
447
|
+
};
|
|
448
|
+
MethodManager.prototype.markReadyFailure = function (error) {
|
|
449
|
+
if (this._ready) {
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
this._readyError = error;
|
|
453
|
+
this._readyEmitter.emit('readyError', error);
|
|
454
|
+
this._readyEmitter.removeAllListeners('ready');
|
|
455
|
+
this._readyEmitter.removeAllListeners('readyError');
|
|
456
|
+
};
|
|
457
|
+
MethodManager.prototype.onReady = function (callback) {
|
|
458
|
+
var _this = this;
|
|
459
|
+
if (this._ready) {
|
|
460
|
+
callback();
|
|
461
|
+
return function () { };
|
|
462
|
+
}
|
|
463
|
+
if (this._readyError) {
|
|
464
|
+
return function () { };
|
|
465
|
+
}
|
|
466
|
+
var handleReady = function () {
|
|
467
|
+
callback();
|
|
468
|
+
};
|
|
469
|
+
this._readyEmitter.once('ready', handleReady);
|
|
470
|
+
return function () {
|
|
471
|
+
_this._readyEmitter.removeListener('ready', handleReady);
|
|
472
|
+
};
|
|
473
|
+
};
|
|
474
|
+
MethodManager.prototype.waitForReadyEvent = function () {
|
|
475
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
476
|
+
return __generator(this, function (_a) {
|
|
477
|
+
switch (_a.label) {
|
|
478
|
+
case 0: return [4 /*yield*/, (0, events_1.once)(this._readyEmitter, 'ready')];
|
|
479
|
+
case 1:
|
|
480
|
+
_a.sent();
|
|
481
|
+
return [2 /*return*/];
|
|
482
|
+
}
|
|
483
|
+
});
|
|
484
|
+
});
|
|
485
|
+
};
|
|
486
|
+
MethodManager.prototype.waitForReadyError = function () {
|
|
487
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
488
|
+
var _a, error;
|
|
489
|
+
return __generator(this, function (_b) {
|
|
490
|
+
switch (_b.label) {
|
|
491
|
+
case 0: return [4 /*yield*/, (0, events_1.once)(this._readyEmitter, 'readyError')];
|
|
492
|
+
case 1:
|
|
493
|
+
_a = __read.apply(void 0, [_b.sent(), 1]), error = _a[0];
|
|
494
|
+
throw error || new Error('MethodManager failed to initialize');
|
|
495
|
+
}
|
|
496
|
+
});
|
|
497
|
+
});
|
|
498
|
+
};
|
|
499
|
+
MethodManager.prototype.waitForReadyTimeout = function (timeoutMs) {
|
|
500
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
501
|
+
return __generator(this, function (_a) {
|
|
502
|
+
switch (_a.label) {
|
|
503
|
+
case 0: return [4 /*yield*/, (0, promises_1.setTimeout)(timeoutMs)];
|
|
504
|
+
case 1:
|
|
505
|
+
_a.sent();
|
|
506
|
+
throw new Error('MethodManager ready timeout');
|
|
507
|
+
}
|
|
508
|
+
});
|
|
509
|
+
});
|
|
510
|
+
};
|
|
511
|
+
MethodManager.prototype.isReady = function () {
|
|
512
|
+
return this._ready;
|
|
513
|
+
};
|
|
514
|
+
MethodManager.prototype.getReadyError = function () {
|
|
515
|
+
return this._readyError;
|
|
516
|
+
};
|
|
517
|
+
MethodManager.prototype.waitUntilReady = function () {
|
|
518
|
+
return __awaiter(this, arguments, void 0, function (timeoutMs) {
|
|
519
|
+
if (timeoutMs === void 0) { timeoutMs = 30000; }
|
|
520
|
+
return __generator(this, function (_a) {
|
|
521
|
+
switch (_a.label) {
|
|
522
|
+
case 0:
|
|
523
|
+
if (this._ready) {
|
|
524
|
+
return [2 /*return*/];
|
|
525
|
+
}
|
|
526
|
+
if (this._readyError) {
|
|
527
|
+
throw this._readyError;
|
|
528
|
+
}
|
|
529
|
+
if (!(!timeoutMs || timeoutMs <= 0)) return [3 /*break*/, 2];
|
|
530
|
+
return [4 /*yield*/, Promise.race([
|
|
531
|
+
this.waitForReadyEvent(),
|
|
532
|
+
this.waitForReadyError()
|
|
533
|
+
])];
|
|
534
|
+
case 1:
|
|
535
|
+
_a.sent();
|
|
536
|
+
return [2 /*return*/];
|
|
537
|
+
case 2: return [4 /*yield*/, Promise.race([
|
|
538
|
+
this.waitForReadyEvent(),
|
|
539
|
+
this.waitForReadyError(),
|
|
540
|
+
this.waitForReadyTimeout(timeoutMs)
|
|
541
|
+
])];
|
|
542
|
+
case 3:
|
|
543
|
+
_a.sent();
|
|
544
|
+
return [2 /*return*/];
|
|
545
|
+
}
|
|
546
|
+
});
|
|
547
|
+
});
|
|
548
|
+
};
|
|
426
549
|
MethodManager.prototype.getMethod = function (methodName) {
|
|
427
550
|
return this._methods[methodName];
|
|
428
551
|
};
|
|
@@ -686,7 +809,7 @@ var MethodManager = /** @class */ (function () {
|
|
|
686
809
|
!methodName.startsWith('monitor-') &&
|
|
687
810
|
!methodName.startsWith('log');
|
|
688
811
|
executeWithExistingSession_1 = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
689
|
-
var monitor, res,
|
|
812
|
+
var monitor, res, error_3, err_3, _a, normalizedError, resolvedCorrelationId, error_4;
|
|
690
813
|
var _b;
|
|
691
814
|
return __generator(this, function (_c) {
|
|
692
815
|
switch (_c.label) {
|
|
@@ -716,8 +839,8 @@ var MethodManager = /** @class */ (function () {
|
|
|
716
839
|
_c.sent();
|
|
717
840
|
return [3 /*break*/, 6];
|
|
718
841
|
case 5:
|
|
719
|
-
|
|
720
|
-
console.error('Error recording text message metric:',
|
|
842
|
+
error_3 = _c.sent();
|
|
843
|
+
console.error('Error recording text message metric:', error_3);
|
|
721
844
|
return [3 /*break*/, 6];
|
|
722
845
|
case 6: return [2 /*return*/, res];
|
|
723
846
|
case 7:
|
|
@@ -760,8 +883,8 @@ var MethodManager = /** @class */ (function () {
|
|
|
760
883
|
_c.sent();
|
|
761
884
|
return [3 /*break*/, 12];
|
|
762
885
|
case 11:
|
|
763
|
-
|
|
764
|
-
console.error('Error recording text message metric:',
|
|
886
|
+
error_4 = _c.sent();
|
|
887
|
+
console.error('Error recording text message metric:', error_4);
|
|
765
888
|
return [3 /*break*/, 12];
|
|
766
889
|
case 12:
|
|
767
890
|
if (!!process.env.IS_WORKER_INSTANCE) return [3 /*break*/, 14];
|
|
@@ -791,7 +914,7 @@ var MethodManager = /** @class */ (function () {
|
|
|
791
914
|
if (shouldStartTransaction) {
|
|
792
915
|
monitor_2 = null;
|
|
793
916
|
return [2 /*return*/, resolveio_server_app_1.ResolveIOServer.getMongoManager().oneTimeTransaction(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
794
|
-
var res,
|
|
917
|
+
var res, error_5, err_4, _a, normalizedError, resolvedCorrelationId, error_6;
|
|
795
918
|
var _b;
|
|
796
919
|
return __generator(this, function (_c) {
|
|
797
920
|
switch (_c.label) {
|
|
@@ -822,8 +945,8 @@ var MethodManager = /** @class */ (function () {
|
|
|
822
945
|
_c.sent();
|
|
823
946
|
return [3 /*break*/, 6];
|
|
824
947
|
case 5:
|
|
825
|
-
|
|
826
|
-
console.error('Error recording text message metric:',
|
|
948
|
+
error_5 = _c.sent();
|
|
949
|
+
console.error('Error recording text message metric:', error_5);
|
|
827
950
|
return [3 /*break*/, 6];
|
|
828
951
|
case 6: return [2 /*return*/, res];
|
|
829
952
|
case 7:
|
|
@@ -866,8 +989,8 @@ var MethodManager = /** @class */ (function () {
|
|
|
866
989
|
_c.sent();
|
|
867
990
|
return [3 /*break*/, 12];
|
|
868
991
|
case 11:
|
|
869
|
-
|
|
870
|
-
console.error('Error recording text message metric:',
|
|
992
|
+
error_6 = _c.sent();
|
|
993
|
+
console.error('Error recording text message metric:', error_6);
|
|
871
994
|
return [3 /*break*/, 12];
|
|
872
995
|
case 12:
|
|
873
996
|
if (!!process.env.IS_WORKER_INSTANCE) return [3 /*break*/, 14];
|
|
@@ -1209,7 +1332,7 @@ var MethodManager = /** @class */ (function () {
|
|
|
1209
1332
|
}
|
|
1210
1333
|
emailProvider = (!mailOptions.force_ses && this_1._mailerCustom) ? 'custom' : 'ses';
|
|
1211
1334
|
(!mailOptions.force_ses && this_1._mailerCustom ? this_1._mailerCustom : this_1._mailerSES).sendMail(mailOptions, function (err) { return __awaiter(_this, void 0, void 0, function () {
|
|
1212
|
-
var metricStatus,
|
|
1335
|
+
var metricStatus, error_7, error_8;
|
|
1213
1336
|
return __generator(this, function (_a) {
|
|
1214
1337
|
switch (_a.label) {
|
|
1215
1338
|
case 0:
|
|
@@ -1246,12 +1369,12 @@ var MethodManager = /** @class */ (function () {
|
|
|
1246
1369
|
_a.label = 7;
|
|
1247
1370
|
case 7: return [3 /*break*/, 14];
|
|
1248
1371
|
case 8:
|
|
1249
|
-
|
|
1250
|
-
console.error('Error in sendMail callback:',
|
|
1372
|
+
error_7 = _a.sent();
|
|
1373
|
+
console.error('Error in sendMail callback:', error_7);
|
|
1251
1374
|
return [4 /*yield*/, email_history_collection_1.EmailHistories.updateOne({ _id: emailHistory._id }, {
|
|
1252
1375
|
$set: {
|
|
1253
1376
|
status: 'failed',
|
|
1254
|
-
error: typeof
|
|
1377
|
+
error: typeof error_7 === 'string' ? error_7 : this.safeStringify(error_7),
|
|
1255
1378
|
completedAt: new Date(),
|
|
1256
1379
|
},
|
|
1257
1380
|
})];
|
|
@@ -1271,8 +1394,8 @@ var MethodManager = /** @class */ (function () {
|
|
|
1271
1394
|
_a.sent();
|
|
1272
1395
|
return [3 /*break*/, 13];
|
|
1273
1396
|
case 12:
|
|
1274
|
-
|
|
1275
|
-
console.error('Error recording email metric:',
|
|
1397
|
+
error_8 = _a.sent();
|
|
1398
|
+
console.error('Error recording email metric:', error_8);
|
|
1276
1399
|
return [3 /*break*/, 13];
|
|
1277
1400
|
case 13: return [7 /*endfinally*/];
|
|
1278
1401
|
case 14: return [2 /*return*/];
|