@resolveio/server-lib 20.12.12 → 20.12.13
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.
|
@@ -508,11 +508,10 @@ var MethodManager = /** @class */ (function () {
|
|
|
508
508
|
};
|
|
509
509
|
MethodManager.prototype.callMethodInternal = function (correlationId, methodName, methodData) {
|
|
510
510
|
return __awaiter(this, void 0, void 0, function () {
|
|
511
|
-
var method, functionMethodData, session,
|
|
512
|
-
var _b;
|
|
511
|
+
var method, methodCallback, functionMethodData, session, shouldStartTransaction, executeWithExistingSession, monitor_2;
|
|
513
512
|
var _this = this;
|
|
514
|
-
return __generator(this, function (
|
|
515
|
-
switch (
|
|
513
|
+
return __generator(this, function (_a) {
|
|
514
|
+
switch (_a.label) {
|
|
516
515
|
case 0:
|
|
517
516
|
method = this.getMethod(methodName);
|
|
518
517
|
if (!method) {
|
|
@@ -576,15 +575,16 @@ var MethodManager = /** @class */ (function () {
|
|
|
576
575
|
correlationId: correlationId
|
|
577
576
|
})];
|
|
578
577
|
case 2:
|
|
579
|
-
|
|
580
|
-
|
|
578
|
+
_a.sent();
|
|
579
|
+
_a.label = 3;
|
|
581
580
|
case 3:
|
|
582
581
|
;
|
|
583
|
-
|
|
582
|
+
_a.label = 4;
|
|
584
583
|
case 4:
|
|
585
|
-
|
|
584
|
+
methodCallback = typeof (methodData[methodData.length - 1]) === 'function' ? methodData[methodData.length - 1] : null;
|
|
585
|
+
functionMethodData = methodCallback ? methodData.slice(0, -1) : methodData;
|
|
586
586
|
session = resolveio_server_app_1.ResolveIOServer.getMongoManager().getSession();
|
|
587
|
-
|
|
587
|
+
shouldStartTransaction = !method.bypassSession &&
|
|
588
588
|
!session &&
|
|
589
589
|
![
|
|
590
590
|
'insertErrorLog', // CIRCULAR LOOP - DO NOT REMOVE
|
|
@@ -592,133 +592,155 @@ var MethodManager = /** @class */ (function () {
|
|
|
592
592
|
'sendEmail' // ALWAYS SEND SO ALWAYS HAVE RECORD - DONT ROLL BACK - BYPASS SESSION
|
|
593
593
|
].includes(methodName) &&
|
|
594
594
|
!methodName.startsWith('monitor-') &&
|
|
595
|
-
!methodName.startsWith('log')
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
res
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
595
|
+
!methodName.startsWith('log');
|
|
596
|
+
executeWithExistingSession = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
597
|
+
var monitor, res, err_3, _a, normalizedError, resolvedCorrelationId;
|
|
598
|
+
var _b;
|
|
599
|
+
return __generator(this, function (_c) {
|
|
600
|
+
switch (_c.label) {
|
|
601
|
+
case 0:
|
|
602
|
+
monitor = this._monitorManagerFunction.startMonitorFunction('Method', methodName, this['user'] || '', '', functionMethodData);
|
|
603
|
+
_c.label = 1;
|
|
604
|
+
case 1:
|
|
605
|
+
_c.trys.push([1, 3, 7, 9]);
|
|
606
|
+
return [4 /*yield*/, (_b = method.function).call.apply(_b, __spreadArray([Object.assign({}, this, MethodManager.prototype)], __read(functionMethodData), false))];
|
|
607
|
+
case 2:
|
|
608
|
+
res = _c.sent();
|
|
609
|
+
if (methodCallback) {
|
|
610
|
+
methodCallback(null, res);
|
|
611
|
+
}
|
|
612
|
+
return [2 /*return*/, res];
|
|
613
|
+
case 3:
|
|
614
|
+
err_3 = _c.sent();
|
|
615
|
+
if (err_3.code === 112 || err_3.codeName === 'WriteConflict' || err_3.code === 251 || err_3.codeName === 'NoSuchTransaction') {
|
|
616
|
+
throw err_3; // Write error, retry
|
|
617
|
+
}
|
|
618
|
+
_a = (0, error_tracking_1.ensureErrorWithCorrelation)(err_3, correlationId), normalizedError = _a.error, resolvedCorrelationId = _a.correlationId;
|
|
619
|
+
console.log(JSON.stringify([new Date(), 'Error Method Manager - Run Method - Existing Session', methodName, {
|
|
620
|
+
code: normalizedError.code,
|
|
621
|
+
codeName: normalizedError.codeName,
|
|
622
|
+
message: normalizedError.message,
|
|
623
|
+
stack: normalizedError.stack,
|
|
624
|
+
correlationId: resolvedCorrelationId
|
|
625
|
+
}], null, 2));
|
|
626
|
+
return [4 /*yield*/, this.reportMethodError('SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], resolvedCorrelationId, {
|
|
627
|
+
message: 'Error detected during method execution (existing session)',
|
|
628
|
+
method: methodName,
|
|
629
|
+
data: methodData,
|
|
630
|
+
error: normalizedError
|
|
631
|
+
}, { context: 'callMethod-existing-session', methodName: methodName }, normalizedError.stack)];
|
|
632
|
+
case 4:
|
|
633
|
+
_c.sent();
|
|
634
|
+
normalizedError.message = "".concat(new Date().toISOString(), " - Error in Method (").concat(methodName, ") - Existing Session: ").concat(normalizedError.message);
|
|
635
|
+
if (methodCallback) {
|
|
636
|
+
methodCallback(normalizedError, null);
|
|
637
|
+
}
|
|
638
|
+
if (!!process.env.IS_WORKER_INSTANCE) return [3 /*break*/, 6];
|
|
639
|
+
return [4 /*yield*/, this.callMethod('insertErrorLog', "Error in Method: ".concat(methodName), {
|
|
640
|
+
method: methodName,
|
|
641
|
+
methodData: methodData,
|
|
642
|
+
error: {
|
|
624
643
|
message: normalizedError.message,
|
|
625
644
|
stack: normalizedError.stack,
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
+
code: normalizedError.code,
|
|
646
|
+
codeName: normalizedError.codeName
|
|
647
|
+
},
|
|
648
|
+
correlationId: resolvedCorrelationId
|
|
649
|
+
})];
|
|
650
|
+
case 5:
|
|
651
|
+
_c.sent();
|
|
652
|
+
_c.label = 6;
|
|
653
|
+
case 6: throw normalizedError;
|
|
654
|
+
case 7: return [4 /*yield*/, this._monitorManagerFunction.finishMonitorFunction(monitor)];
|
|
655
|
+
case 8:
|
|
656
|
+
_c.sent();
|
|
657
|
+
return [7 /*endfinally*/];
|
|
658
|
+
case 9: return [2 /*return*/];
|
|
659
|
+
}
|
|
660
|
+
});
|
|
661
|
+
}); };
|
|
662
|
+
if (shouldStartTransaction) {
|
|
663
|
+
monitor_2 = null;
|
|
664
|
+
return [2 /*return*/, resolveio_server_app_1.ResolveIOServer.getMongoManager().oneTimeTransaction(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
665
|
+
var res, err_4, _a, normalizedError, resolvedCorrelationId;
|
|
666
|
+
var _b;
|
|
667
|
+
return __generator(this, function (_c) {
|
|
668
|
+
switch (_c.label) {
|
|
669
|
+
case 0:
|
|
670
|
+
// console.log(new Date(), 'Calling Method - New Session', methodName);
|
|
671
|
+
monitor_2 = this._monitorManagerFunction.startMonitorFunction('Method', methodName, this['user'] || '', '', functionMethodData);
|
|
672
|
+
_c.label = 1;
|
|
673
|
+
case 1:
|
|
674
|
+
_c.trys.push([1, 3, 7, 9]);
|
|
675
|
+
return [4 /*yield*/, (_b = method.function).call.apply(_b, __spreadArray([Object.assign({}, this, MethodManager.prototype)], __read(functionMethodData), false))];
|
|
676
|
+
case 2:
|
|
677
|
+
res = _c.sent();
|
|
678
|
+
if (methodCallback) {
|
|
679
|
+
methodCallback(null, res);
|
|
680
|
+
}
|
|
681
|
+
return [2 /*return*/, res];
|
|
682
|
+
case 3:
|
|
683
|
+
err_4 = _c.sent();
|
|
684
|
+
if (err_4.code === 112 || err_4.codeName === 'WriteConflict' || err_4.code === 251 || err_4.codeName === 'NoSuchTransaction') {
|
|
685
|
+
throw err_4; // Write error, retry
|
|
686
|
+
}
|
|
687
|
+
_a = (0, error_tracking_1.ensureErrorWithCorrelation)(err_4, correlationId), normalizedError = _a.error, resolvedCorrelationId = _a.correlationId;
|
|
688
|
+
console.log(JSON.stringify([new Date(), 'Error Method Manager - Run Method - New Session', methodName, {
|
|
689
|
+
code: normalizedError.code,
|
|
690
|
+
codeName: normalizedError.codeName,
|
|
645
691
|
message: normalizedError.message,
|
|
646
692
|
stack: normalizedError.stack,
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
693
|
+
correlationId: resolvedCorrelationId
|
|
694
|
+
}], null, 2));
|
|
695
|
+
return [4 /*yield*/, this.reportMethodError('SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], resolvedCorrelationId, {
|
|
696
|
+
message: 'Error detected during method execution (new session)',
|
|
697
|
+
method: methodName,
|
|
698
|
+
data: methodData,
|
|
699
|
+
error: normalizedError
|
|
700
|
+
}, { context: 'callMethod-new-session', methodName: methodName }, normalizedError.stack)];
|
|
701
|
+
case 4:
|
|
702
|
+
_c.sent();
|
|
703
|
+
normalizedError.message = "".concat(new Date().toISOString(), " - Error in Method With Session (").concat(methodName, ") - New Session: ").concat(normalizedError.message);
|
|
704
|
+
if (methodCallback) {
|
|
705
|
+
methodCallback(normalizedError, null);
|
|
706
|
+
}
|
|
707
|
+
if (!!process.env.IS_WORKER_INSTANCE) return [3 /*break*/, 6];
|
|
708
|
+
return [4 /*yield*/, this.callMethod('insertErrorLog', "Error in Method: ".concat(methodName), {
|
|
709
|
+
method: methodName,
|
|
710
|
+
methodData: methodData,
|
|
711
|
+
error: {
|
|
712
|
+
message: normalizedError.message,
|
|
713
|
+
stack: normalizedError.stack,
|
|
714
|
+
code: normalizedError.code,
|
|
715
|
+
codeName: normalizedError.codeName
|
|
716
|
+
},
|
|
717
|
+
correlationId: resolvedCorrelationId
|
|
718
|
+
})];
|
|
719
|
+
case 5:
|
|
720
|
+
_c.sent();
|
|
721
|
+
_c.label = 6;
|
|
722
|
+
case 6: throw normalizedError;
|
|
723
|
+
case 7: return [4 /*yield*/, this._monitorManagerFunction.finishMonitorFunction(monitor_2)];
|
|
724
|
+
case 8:
|
|
725
|
+
_c.sent();
|
|
726
|
+
return [7 /*endfinally*/];
|
|
727
|
+
case 9: return [2 /*return*/];
|
|
728
|
+
}
|
|
729
|
+
});
|
|
730
|
+
}); })];
|
|
674
731
|
}
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
732
|
+
else if (method.bypassSession && session) {
|
|
733
|
+
return [2 /*return*/, resolveio_server_app_1.ResolveIOServer.getMongoManager().runWithoutSession(function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
734
|
+
switch (_a.label) {
|
|
735
|
+
case 0: return [4 /*yield*/, executeWithExistingSession()];
|
|
736
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
737
|
+
}
|
|
738
|
+
}); }); })];
|
|
680
739
|
}
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
code: normalizedError.code,
|
|
684
|
-
codeName: normalizedError.codeName,
|
|
685
|
-
message: normalizedError.message,
|
|
686
|
-
stack: normalizedError.stack,
|
|
687
|
-
correlationId: resolvedCorrelationId
|
|
688
|
-
}], null, 2));
|
|
689
|
-
return [4 /*yield*/, this.reportMethodError('SERVER - Error Detected - ' + this.serverConfig['CLIENT_NAME'], resolvedCorrelationId, {
|
|
690
|
-
message: 'Error detected during method execution (existing session)',
|
|
691
|
-
method: methodName,
|
|
692
|
-
data: methodData,
|
|
693
|
-
error: normalizedError
|
|
694
|
-
}, { context: 'callMethod-existing-session', methodName: methodName }, normalizedError.stack)];
|
|
695
|
-
case 9:
|
|
696
|
-
_c.sent();
|
|
697
|
-
normalizedError.message = "".concat(new Date().toISOString(), " - Error in Method (").concat(methodName, ") - Existing Session: ").concat(normalizedError.message);
|
|
698
|
-
if (methodData[methodData.length - 1] && typeof (methodData[methodData.length - 1]) === 'function') {
|
|
699
|
-
methodData[methodData.length - 1](normalizedError, null);
|
|
740
|
+
else {
|
|
741
|
+
return [2 /*return*/, executeWithExistingSession()];
|
|
700
742
|
}
|
|
701
|
-
|
|
702
|
-
return [4 /*yield*/, this.callMethod('insertErrorLog', "Error in Method: ".concat(methodName), {
|
|
703
|
-
method: methodName,
|
|
704
|
-
methodData: methodData,
|
|
705
|
-
error: {
|
|
706
|
-
message: normalizedError.message,
|
|
707
|
-
stack: normalizedError.stack,
|
|
708
|
-
code: normalizedError.code,
|
|
709
|
-
codeName: normalizedError.codeName
|
|
710
|
-
},
|
|
711
|
-
correlationId: resolvedCorrelationId
|
|
712
|
-
})];
|
|
713
|
-
case 10:
|
|
714
|
-
_c.sent();
|
|
715
|
-
_c.label = 11;
|
|
716
|
-
case 11: throw normalizedError;
|
|
717
|
-
case 12: return [4 /*yield*/, this._monitorManagerFunction.finishMonitorFunction(monitor)];
|
|
718
|
-
case 13:
|
|
719
|
-
_c.sent();
|
|
720
|
-
return [7 /*endfinally*/];
|
|
721
|
-
case 14: return [2 /*return*/];
|
|
743
|
+
return [2 /*return*/];
|
|
722
744
|
}
|
|
723
745
|
});
|
|
724
746
|
});
|