@resolveio/server-lib 12.7.20 → 12.8.0
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/cron.manager.js +80 -65
- package/managers/cron.manager.js.map +1 -1
- package/managers/mongo.manager.js +17 -10
- package/managers/mongo.manager.js.map +1 -1
- package/managers/subscription.manager.d.ts +1 -1
- package/managers/subscription.manager.js +141 -120
- package/managers/subscription.manager.js.map +1 -1
- package/package.json +1 -1
- package/server-app.js +17 -8
- package/server-app.js.map +1 -1
|
@@ -718,134 +718,155 @@ var SubscriptionManager = /** @class */ (function () {
|
|
|
718
718
|
};
|
|
719
719
|
// Watch (tail) Mongo's operation log on the entire database (all insert/modify/delete will trigger this function)
|
|
720
720
|
SubscriptionManager.prototype.tailOpLog = function (resumeToken) {
|
|
721
|
-
|
|
722
|
-
if (!this._oplog || this._oplog.closed) {
|
|
723
|
-
this._oplogRetryCount += 1;
|
|
724
|
-
if (this._oplogRetryCount > 10) {
|
|
725
|
-
console.error('****************** TAIL OPLOG ERROR, RETRYING A BUNCH OF TIMES, KILLING PROCESS **************************');
|
|
726
|
-
process.exit(1);
|
|
727
|
-
}
|
|
721
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
728
722
|
var lastResumeToken_1;
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
}
|
|
738
|
-
else {
|
|
739
|
-
this._oplog = index_1.ResolveIOServer.getMainDB().watch();
|
|
740
|
-
}
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
|
-
else {
|
|
744
|
-
this._oplog = index_1.ResolveIOServer.getMainDB().watch();
|
|
745
|
-
}
|
|
746
|
-
console.log(new Date(), 'oplog started');
|
|
747
|
-
this._oplog.on('change', function (doc) {
|
|
748
|
-
// let startDate = new Date();
|
|
749
|
-
if (doc.ns) {
|
|
750
|
-
var collection = doc.ns.coll;
|
|
751
|
-
if (!_this._debugOplogCollections.some(function (a) { return a.collection === doc.ns.coll && a.type === doc.operationType; })) {
|
|
752
|
-
_this._debugOplogCollections.push({
|
|
753
|
-
collection: doc.ns.coll,
|
|
754
|
-
type: doc.operationType,
|
|
755
|
-
hits: 1
|
|
756
|
-
});
|
|
757
|
-
}
|
|
758
|
-
else {
|
|
759
|
-
_this._debugOplogCollections.filter(function (a) { return a.collection === doc.ns.coll && a.type === doc.operationType; })[0].hits += 1;
|
|
760
|
-
}
|
|
761
|
-
// console.log(new Date(), 'Op log doc', doc.operationType, collection);
|
|
762
|
-
if (collection && !collection.endsWith('.versions') && !collection.startsWith('monitor-') && collection !== 'logs' && collection !== 'log-method-latencies' && collection !== 'log-subscriptions') {
|
|
763
|
-
_this._debugOplogHits += 1;
|
|
764
|
-
if (doc.operationType === 'insert') {
|
|
765
|
-
if (collection === 'support-tickets') {
|
|
766
|
-
if (_this.serverConfig['ROOT_URL'] === 'https://resolveio.com') {
|
|
767
|
-
_this._mainServer.getMethodManager().callMethodInternal.call(_this._mainServer.getMethodManager(), 'sendSupportTicketEmail', doc.documentKey['_id']);
|
|
768
|
-
_this.invalidatePubsCache(collection, 'insert');
|
|
769
|
-
}
|
|
770
|
-
}
|
|
771
|
-
if (collection !== 'method-responses') {
|
|
772
|
-
_this.invalidatePubsCache(collection, 'insert');
|
|
773
|
-
}
|
|
774
|
-
// let endDate = new Date();
|
|
775
|
-
// this.currentPerfomanceMonitor.push({
|
|
776
|
-
// _id: this.idPerformance++,
|
|
777
|
-
// function: 'oplog',
|
|
778
|
-
// publication: collection,
|
|
779
|
-
// subscriptionData: [],
|
|
780
|
-
// date_start: startDate,
|
|
781
|
-
// date_end: endDate,
|
|
782
|
-
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
783
|
-
// result: 'Insert'
|
|
784
|
-
// });
|
|
785
|
-
}
|
|
786
|
-
else if (doc.operationType === 'update' || doc.operationType === 'replace') {
|
|
787
|
-
if (collection !== 'method-responses') {
|
|
788
|
-
_this.invalidatePubsCache(collection, 'update');
|
|
789
|
-
}
|
|
790
|
-
// let endDate = new Date();
|
|
791
|
-
// this.currentPerfomanceMonitor.push({
|
|
792
|
-
// _id: this.idPerformance++,
|
|
793
|
-
// function: 'oplog',
|
|
794
|
-
// publication: collection,
|
|
795
|
-
// subscriptionData: [],
|
|
796
|
-
// date_start: startDate,
|
|
797
|
-
// date_end: endDate,
|
|
798
|
-
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
799
|
-
// result: 'Update'
|
|
800
|
-
// });
|
|
723
|
+
var _this = this;
|
|
724
|
+
return __generator(this, function (_a) {
|
|
725
|
+
switch (_a.label) {
|
|
726
|
+
case 0:
|
|
727
|
+
if (this._oplog$ && !this._oplog$.closed) {
|
|
728
|
+
this._oplog$.removeAllListeners();
|
|
729
|
+
this._oplog$.close();
|
|
730
|
+
this._oplog$ = null;
|
|
801
731
|
}
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
732
|
+
return [4 /*yield*/, new Promise(function (resolve) { return setTimeout(resolve, 1000); })];
|
|
733
|
+
case 1:
|
|
734
|
+
_a.sent();
|
|
735
|
+
if (!this._oplog$ || this._oplog$.closed) {
|
|
736
|
+
this._oplogRetryCount += 1;
|
|
737
|
+
if (this._oplogRetryCount > 5) {
|
|
738
|
+
console.error('****************** TAIL OPLOG ERROR, RETRYING A BUNCH OF TIMES, KILLING PROCESS **************************');
|
|
739
|
+
process.exit(1);
|
|
805
740
|
}
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
flag_collection_1.Flags.findOne({ type: 'Enable Debug' }).then(function (flag) {
|
|
821
|
-
if (flag && flag.value) {
|
|
822
|
-
_this._enableDebug = true;
|
|
741
|
+
if (resumeToken) {
|
|
742
|
+
lastResumeToken_1 = resumeToken;
|
|
743
|
+
try {
|
|
744
|
+
this._oplog$ = index_1.ResolveIOServer.getMainDB().watch([], { resumeAfter: resumeToken });
|
|
745
|
+
}
|
|
746
|
+
catch (errOp) {
|
|
747
|
+
if (this._oplog$) {
|
|
748
|
+
this._oplog$.removeAllListeners();
|
|
749
|
+
this._oplog$.close();
|
|
750
|
+
this._oplog$ = null;
|
|
751
|
+
}
|
|
752
|
+
this.tailOpLog(resumeToken);
|
|
753
|
+
return [2 /*return*/];
|
|
754
|
+
}
|
|
823
755
|
}
|
|
824
756
|
else {
|
|
825
|
-
|
|
757
|
+
this._oplog$ = index_1.ResolveIOServer.getMainDB().watch();
|
|
826
758
|
}
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
759
|
+
console.log(new Date(), 'oplog started');
|
|
760
|
+
this._oplog$.on('change', function (doc) {
|
|
761
|
+
// let startDate = new Date();
|
|
762
|
+
if (doc.ns) {
|
|
763
|
+
var collection = doc.ns.coll;
|
|
764
|
+
if (!_this._debugOplogCollections.some(function (a) { return a.collection === doc.ns.coll && a.type === doc.operationType; })) {
|
|
765
|
+
_this._debugOplogCollections.push({
|
|
766
|
+
collection: doc.ns.coll,
|
|
767
|
+
type: doc.operationType,
|
|
768
|
+
hits: 1
|
|
769
|
+
});
|
|
770
|
+
}
|
|
771
|
+
else {
|
|
772
|
+
_this._debugOplogCollections.filter(function (a) { return a.collection === doc.ns.coll && a.type === doc.operationType; })[0].hits += 1;
|
|
773
|
+
}
|
|
774
|
+
// console.log(new Date(), 'Op log doc', doc.operationType, collection);
|
|
775
|
+
if (collection && !collection.endsWith('.versions') && !collection.startsWith('monitor-') && collection !== 'logs' && collection !== 'log-method-latencies' && collection !== 'log-subscriptions') {
|
|
776
|
+
_this._debugOplogHits += 1;
|
|
777
|
+
if (doc.operationType === 'insert') {
|
|
778
|
+
if (collection === 'support-tickets') {
|
|
779
|
+
if (_this.serverConfig['ROOT_URL'] === 'https://resolveio.com') {
|
|
780
|
+
_this._mainServer.getMethodManager().callMethodInternal.call(_this._mainServer.getMethodManager(), 'sendSupportTicketEmail', doc.documentKey['_id']);
|
|
781
|
+
_this.invalidatePubsCache(collection, 'insert');
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
if (collection !== 'method-responses') {
|
|
785
|
+
_this.invalidatePubsCache(collection, 'insert');
|
|
786
|
+
}
|
|
787
|
+
// let endDate = new Date();
|
|
788
|
+
// this.currentPerfomanceMonitor.push({
|
|
789
|
+
// _id: this.idPerformance++,
|
|
790
|
+
// function: 'oplog',
|
|
791
|
+
// publication: collection,
|
|
792
|
+
// subscriptionData: [],
|
|
793
|
+
// date_start: startDate,
|
|
794
|
+
// date_end: endDate,
|
|
795
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
796
|
+
// result: 'Insert'
|
|
797
|
+
// });
|
|
798
|
+
}
|
|
799
|
+
else if (doc.operationType === 'update' || doc.operationType === 'replace') {
|
|
800
|
+
if (collection !== 'method-responses') {
|
|
801
|
+
_this.invalidatePubsCache(collection, 'update');
|
|
802
|
+
}
|
|
803
|
+
// let endDate = new Date();
|
|
804
|
+
// this.currentPerfomanceMonitor.push({
|
|
805
|
+
// _id: this.idPerformance++,
|
|
806
|
+
// function: 'oplog',
|
|
807
|
+
// publication: collection,
|
|
808
|
+
// subscriptionData: [],
|
|
809
|
+
// date_start: startDate,
|
|
810
|
+
// date_end: endDate,
|
|
811
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
812
|
+
// result: 'Update'
|
|
813
|
+
// });
|
|
814
|
+
}
|
|
815
|
+
else if (doc.operationType === 'delete') {
|
|
816
|
+
if (collection !== 'method-responses') {
|
|
817
|
+
_this.invalidatePubsCache(collection, 'delete');
|
|
818
|
+
}
|
|
819
|
+
// let endDate = new Date();
|
|
820
|
+
// this.currentPerfomanceMonitor.push({
|
|
821
|
+
// _id: this.idPerformance++,
|
|
822
|
+
// function: 'oplog',
|
|
823
|
+
// publication: collection,
|
|
824
|
+
// subscriptionData: [],
|
|
825
|
+
// date_start: startDate,
|
|
826
|
+
// date_end: endDate,
|
|
827
|
+
// duration: moment(endDate).diff(moment(startDate), 'milliseconds', false),
|
|
828
|
+
// result: 'Delete'
|
|
829
|
+
// });
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
if (collection === 'flags') {
|
|
833
|
+
flag_collection_1.Flags.findOne({ type: 'Enable Debug' }).then(function (flag) {
|
|
834
|
+
if (flag && flag.value) {
|
|
835
|
+
_this._enableDebug = true;
|
|
836
|
+
}
|
|
837
|
+
else {
|
|
838
|
+
_this._enableDebug = false;
|
|
839
|
+
}
|
|
840
|
+
});
|
|
841
|
+
}
|
|
842
|
+
lastResumeToken_1 = doc._id;
|
|
843
|
+
}
|
|
844
|
+
});
|
|
845
|
+
this._oplog$.on('error', function (error) {
|
|
846
|
+
console.log(new Date(), 'oplog error', error);
|
|
847
|
+
_this._oplog$.removeAllListeners();
|
|
848
|
+
_this._oplog$.close();
|
|
849
|
+
_this._oplog$ = null;
|
|
850
|
+
_this.tailOpLog(lastResumeToken_1);
|
|
851
|
+
});
|
|
852
|
+
this._oplog$.on('end', function () {
|
|
853
|
+
console.log(new Date(), 'oplog end');
|
|
854
|
+
_this._oplog$.removeAllListeners();
|
|
855
|
+
_this._oplog$.close();
|
|
856
|
+
_this._oplog$ = null;
|
|
857
|
+
_this.tailOpLog(lastResumeToken_1);
|
|
858
|
+
});
|
|
859
|
+
this._oplog$.on('close', function () {
|
|
860
|
+
console.log(new Date(), 'oplog close');
|
|
861
|
+
_this._oplog$.removeAllListeners();
|
|
862
|
+
_this._oplog$ = null;
|
|
863
|
+
_this.tailOpLog(lastResumeToken_1);
|
|
864
|
+
});
|
|
865
|
+
}
|
|
866
|
+
return [2 /*return*/];
|
|
830
867
|
}
|
|
831
868
|
});
|
|
832
|
-
|
|
833
|
-
console.log(new Date(), 'oplog error', error);
|
|
834
|
-
_this._oplog.close();
|
|
835
|
-
});
|
|
836
|
-
this._oplog.on('end', function () {
|
|
837
|
-
console.log(new Date(), 'oplog end');
|
|
838
|
-
_this._oplog.close();
|
|
839
|
-
});
|
|
840
|
-
this._oplog.on('close', function () {
|
|
841
|
-
_this._oplog = null;
|
|
842
|
-
console.log(new Date(), 'oplog close');
|
|
843
|
-
_this.tailOpLog(lastResumeToken_1);
|
|
844
|
-
});
|
|
845
|
-
}
|
|
846
|
-
else {
|
|
847
|
-
this._oplog.close();
|
|
848
|
-
}
|
|
869
|
+
});
|
|
849
870
|
};
|
|
850
871
|
// Fetch pub once, send to all clients linked to this pub
|
|
851
872
|
SubscriptionManager.prototype.sendDataToOne = function (ws, messageId, subscription, type, collection) {
|