@okf/ootils 1.21.2 → 1.21.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/dist/browser.js +1 -2
- package/dist/browser.mjs +1 -2
- package/dist/node.d.mts +3 -0
- package/dist/node.d.ts +3 -0
- package/dist/node.js +73 -15
- package/dist/node.mjs +73 -15
- package/dist/universal.js +1 -2
- package/dist/universal.mjs +1 -2
- package/package.json +1 -1
package/dist/browser.js
CHANGED
|
@@ -634,8 +634,7 @@ var BASE_BULLMQ_CONFIG = {
|
|
|
634
634
|
}
|
|
635
635
|
},
|
|
636
636
|
workerConfig: {
|
|
637
|
-
concurrency:
|
|
638
|
-
// Sequential processing to avoid MongoDB write conflicts
|
|
637
|
+
concurrency: 100,
|
|
639
638
|
lockDuration: 3e5,
|
|
640
639
|
// 5 minutes lock duration since annotation can be slow
|
|
641
640
|
maxStalledCount: 3
|
package/dist/browser.mjs
CHANGED
|
@@ -597,8 +597,7 @@ var BASE_BULLMQ_CONFIG = {
|
|
|
597
597
|
}
|
|
598
598
|
},
|
|
599
599
|
workerConfig: {
|
|
600
|
-
concurrency:
|
|
601
|
-
// Sequential processing to avoid MongoDB write conflicts
|
|
600
|
+
concurrency: 100,
|
|
602
601
|
lockDuration: 3e5,
|
|
603
602
|
// 5 minutes lock duration since annotation can be slow
|
|
604
603
|
maxStalledCount: 3
|
package/dist/node.d.mts
CHANGED
|
@@ -763,6 +763,7 @@ declare class MongoConnector {
|
|
|
763
763
|
static getEnv(): any;
|
|
764
764
|
static getDbConfigs(): any;
|
|
765
765
|
static getTenantToClusterMapping(): any;
|
|
766
|
+
static isClusterUnavailable(clusterName: any): any;
|
|
766
767
|
constructor(options: any);
|
|
767
768
|
clusterConnections: {};
|
|
768
769
|
env: any;
|
|
@@ -775,7 +776,9 @@ declare class MongoConnector {
|
|
|
775
776
|
*/
|
|
776
777
|
multiConnectToMongoDB(): {};
|
|
777
778
|
multiConnectToMongoDBAsync(): Promise<{}>;
|
|
779
|
+
failedOptionalClusters: Set<any> | undefined;
|
|
778
780
|
initiateConnectionEventListeners: (CLUSTER_NAME: any) => void;
|
|
781
|
+
initiateOptionalConnectionEventListeners: (CLUSTER_NAME: any) => void;
|
|
779
782
|
/**
|
|
780
783
|
* Helper function to close clusterConnections object
|
|
781
784
|
*/
|
package/dist/node.d.ts
CHANGED
|
@@ -763,6 +763,7 @@ declare class MongoConnector {
|
|
|
763
763
|
static getEnv(): any;
|
|
764
764
|
static getDbConfigs(): any;
|
|
765
765
|
static getTenantToClusterMapping(): any;
|
|
766
|
+
static isClusterUnavailable(clusterName: any): any;
|
|
766
767
|
constructor(options: any);
|
|
767
768
|
clusterConnections: {};
|
|
768
769
|
env: any;
|
|
@@ -775,7 +776,9 @@ declare class MongoConnector {
|
|
|
775
776
|
*/
|
|
776
777
|
multiConnectToMongoDB(): {};
|
|
777
778
|
multiConnectToMongoDBAsync(): Promise<{}>;
|
|
779
|
+
failedOptionalClusters: Set<any> | undefined;
|
|
778
780
|
initiateConnectionEventListeners: (CLUSTER_NAME: any) => void;
|
|
781
|
+
initiateOptionalConnectionEventListeners: (CLUSTER_NAME: any) => void;
|
|
779
782
|
/**
|
|
780
783
|
* Helper function to close clusterConnections object
|
|
781
784
|
*/
|
package/dist/node.js
CHANGED
|
@@ -237,8 +237,7 @@ var init_GLOBAL_BULLMQ_CONFIG = __esm({
|
|
|
237
237
|
}
|
|
238
238
|
},
|
|
239
239
|
workerConfig: {
|
|
240
|
-
concurrency:
|
|
241
|
-
// Sequential processing to avoid MongoDB write conflicts
|
|
240
|
+
concurrency: 100,
|
|
242
241
|
lockDuration: 3e5,
|
|
243
242
|
// 5 minutes lock duration since annotation can be slow
|
|
244
243
|
maxStalledCount: 3
|
|
@@ -701,6 +700,26 @@ var require_MongoConnector = __commonJS({
|
|
|
701
700
|
console.log(`\u{1F504} Mongoose reconnected to ${CLUSTER_NAME}`);
|
|
702
701
|
});
|
|
703
702
|
});
|
|
703
|
+
__publicField(this, "initiateOptionalConnectionEventListeners", (CLUSTER_NAME) => {
|
|
704
|
+
this.clusterConnections[CLUSTER_NAME].on("open", () => {
|
|
705
|
+
console.log(`\u2705 Mongoose connection open to optional cluster ${CLUSTER_NAME}`);
|
|
706
|
+
this.failedOptionalClusters?.delete(CLUSTER_NAME);
|
|
707
|
+
});
|
|
708
|
+
this.clusterConnections[CLUSTER_NAME].on("error", (err) => {
|
|
709
|
+
console.warn(
|
|
710
|
+
`\u26A0\uFE0F Mongoose connection error on optional cluster ${CLUSTER_NAME}: ${err.message}`
|
|
711
|
+
);
|
|
712
|
+
this.failedOptionalClusters?.add(CLUSTER_NAME);
|
|
713
|
+
});
|
|
714
|
+
this.clusterConnections[CLUSTER_NAME].on("disconnected", () => {
|
|
715
|
+
console.log(`\u{1F50C} Mongoose disconnected from optional cluster ${CLUSTER_NAME}`);
|
|
716
|
+
this.failedOptionalClusters?.add(CLUSTER_NAME);
|
|
717
|
+
});
|
|
718
|
+
this.clusterConnections[CLUSTER_NAME].on("reconnected", () => {
|
|
719
|
+
console.log(`\u{1F504} Mongoose reconnected to optional cluster ${CLUSTER_NAME}`);
|
|
720
|
+
this.failedOptionalClusters?.delete(CLUSTER_NAME);
|
|
721
|
+
});
|
|
722
|
+
});
|
|
704
723
|
this.clusterConnections = {};
|
|
705
724
|
this.env = options.env;
|
|
706
725
|
this.dbConfigs = options.dbConfigs;
|
|
@@ -754,29 +773,62 @@ var require_MongoConnector = __commonJS({
|
|
|
754
773
|
}
|
|
755
774
|
async multiConnectToMongoDBAsync() {
|
|
756
775
|
const allClusterConfigs = Object.values(this.dbConfigs);
|
|
776
|
+
this.failedOptionalClusters = /* @__PURE__ */ new Set();
|
|
757
777
|
await Promise.all(
|
|
758
778
|
allClusterConfigs.map(async (clusterConf) => {
|
|
759
|
-
const { CLUSTER_NAME, CLUSTER_URI } = clusterConf;
|
|
779
|
+
const { CLUSTER_NAME, CLUSTER_URI, optional } = clusterConf;
|
|
760
780
|
if (!CLUSTER_NAME || !CLUSTER_URI) {
|
|
761
781
|
throw new Error(
|
|
762
782
|
`Missing CLUSTER_NAME or CLUSTER_URI in cluster conf: ${JSON.stringify(clusterConf)}`
|
|
763
783
|
);
|
|
764
784
|
}
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
785
|
+
try {
|
|
786
|
+
const connection = mongoose5.createConnection(CLUSTER_URI, this.mongoOptions);
|
|
787
|
+
this.clusterConnections[CLUSTER_NAME] = connection;
|
|
788
|
+
if (!optional) {
|
|
789
|
+
this.initiateConnectionEventListeners(CLUSTER_NAME);
|
|
790
|
+
} else {
|
|
791
|
+
this.initiateOptionalConnectionEventListeners(CLUSTER_NAME);
|
|
792
|
+
}
|
|
793
|
+
await new Promise((resolve, reject) => {
|
|
794
|
+
connection.once("open", () => {
|
|
795
|
+
console.log(`Connected to MongoDB: ${CLUSTER_NAME}`);
|
|
796
|
+
resolve();
|
|
797
|
+
});
|
|
798
|
+
connection.once("error", (err) => {
|
|
799
|
+
if (optional) {
|
|
800
|
+
console.warn(`\u26A0\uFE0F Optional cluster ${CLUSTER_NAME} failed to connect: ${err.message}`);
|
|
801
|
+
resolve();
|
|
802
|
+
} else {
|
|
803
|
+
reject(err);
|
|
804
|
+
}
|
|
805
|
+
});
|
|
772
806
|
});
|
|
773
|
-
|
|
774
|
-
|
|
807
|
+
} catch (err) {
|
|
808
|
+
if (optional) {
|
|
809
|
+
console.warn(`\u26A0\uFE0F Optional cluster ${CLUSTER_NAME} failed to connect: ${err.message}`);
|
|
810
|
+
this.failedOptionalClusters.add(CLUSTER_NAME);
|
|
811
|
+
delete this.clusterConnections[CLUSTER_NAME];
|
|
812
|
+
} else {
|
|
813
|
+
throw err;
|
|
814
|
+
}
|
|
815
|
+
}
|
|
775
816
|
})
|
|
776
817
|
);
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
818
|
+
for (const clusterName of this.failedOptionalClusters) {
|
|
819
|
+
delete this.clusterConnections[clusterName];
|
|
820
|
+
}
|
|
821
|
+
const optionalFailedCount = this.failedOptionalClusters.size;
|
|
822
|
+
const connectedCount = Object.keys(this.clusterConnections).length;
|
|
823
|
+
if (optionalFailedCount > 0) {
|
|
824
|
+
console.log(
|
|
825
|
+
`\u{1F389} Connected to ${connectedCount} MongoDB databases (${optionalFailedCount} optional cluster(s) unavailable)`
|
|
826
|
+
);
|
|
827
|
+
} else {
|
|
828
|
+
console.log(
|
|
829
|
+
`\u{1F389} Connected to ${connectedCount} MongoDB databases`
|
|
830
|
+
);
|
|
831
|
+
}
|
|
780
832
|
return this.clusterConnections;
|
|
781
833
|
}
|
|
782
834
|
// Static method to get the full instance
|
|
@@ -813,6 +865,12 @@ var require_MongoConnector = __commonJS({
|
|
|
813
865
|
}
|
|
814
866
|
return _MongoConnector.instance.tenantToClusterMapping;
|
|
815
867
|
}
|
|
868
|
+
static isClusterUnavailable(clusterName) {
|
|
869
|
+
if (!_MongoConnector.instance) {
|
|
870
|
+
throw new Error("MongoConnector not initialized");
|
|
871
|
+
}
|
|
872
|
+
return _MongoConnector.instance.failedOptionalClusters?.has(clusterName) || !_MongoConnector.instance.clusterConnections[clusterName];
|
|
873
|
+
}
|
|
816
874
|
/**
|
|
817
875
|
* Helper function to close clusterConnections object
|
|
818
876
|
*/
|
package/dist/node.mjs
CHANGED
|
@@ -242,8 +242,7 @@ var init_GLOBAL_BULLMQ_CONFIG = __esm({
|
|
|
242
242
|
}
|
|
243
243
|
},
|
|
244
244
|
workerConfig: {
|
|
245
|
-
concurrency:
|
|
246
|
-
// Sequential processing to avoid MongoDB write conflicts
|
|
245
|
+
concurrency: 100,
|
|
247
246
|
lockDuration: 3e5,
|
|
248
247
|
// 5 minutes lock duration since annotation can be slow
|
|
249
248
|
maxStalledCount: 3
|
|
@@ -706,6 +705,26 @@ var require_MongoConnector = __commonJS({
|
|
|
706
705
|
console.log(`\u{1F504} Mongoose reconnected to ${CLUSTER_NAME}`);
|
|
707
706
|
});
|
|
708
707
|
});
|
|
708
|
+
__publicField(this, "initiateOptionalConnectionEventListeners", (CLUSTER_NAME) => {
|
|
709
|
+
this.clusterConnections[CLUSTER_NAME].on("open", () => {
|
|
710
|
+
console.log(`\u2705 Mongoose connection open to optional cluster ${CLUSTER_NAME}`);
|
|
711
|
+
this.failedOptionalClusters?.delete(CLUSTER_NAME);
|
|
712
|
+
});
|
|
713
|
+
this.clusterConnections[CLUSTER_NAME].on("error", (err) => {
|
|
714
|
+
console.warn(
|
|
715
|
+
`\u26A0\uFE0F Mongoose connection error on optional cluster ${CLUSTER_NAME}: ${err.message}`
|
|
716
|
+
);
|
|
717
|
+
this.failedOptionalClusters?.add(CLUSTER_NAME);
|
|
718
|
+
});
|
|
719
|
+
this.clusterConnections[CLUSTER_NAME].on("disconnected", () => {
|
|
720
|
+
console.log(`\u{1F50C} Mongoose disconnected from optional cluster ${CLUSTER_NAME}`);
|
|
721
|
+
this.failedOptionalClusters?.add(CLUSTER_NAME);
|
|
722
|
+
});
|
|
723
|
+
this.clusterConnections[CLUSTER_NAME].on("reconnected", () => {
|
|
724
|
+
console.log(`\u{1F504} Mongoose reconnected to optional cluster ${CLUSTER_NAME}`);
|
|
725
|
+
this.failedOptionalClusters?.delete(CLUSTER_NAME);
|
|
726
|
+
});
|
|
727
|
+
});
|
|
709
728
|
this.clusterConnections = {};
|
|
710
729
|
this.env = options.env;
|
|
711
730
|
this.dbConfigs = options.dbConfigs;
|
|
@@ -759,29 +778,62 @@ var require_MongoConnector = __commonJS({
|
|
|
759
778
|
}
|
|
760
779
|
async multiConnectToMongoDBAsync() {
|
|
761
780
|
const allClusterConfigs = Object.values(this.dbConfigs);
|
|
781
|
+
this.failedOptionalClusters = /* @__PURE__ */ new Set();
|
|
762
782
|
await Promise.all(
|
|
763
783
|
allClusterConfigs.map(async (clusterConf) => {
|
|
764
|
-
const { CLUSTER_NAME, CLUSTER_URI } = clusterConf;
|
|
784
|
+
const { CLUSTER_NAME, CLUSTER_URI, optional } = clusterConf;
|
|
765
785
|
if (!CLUSTER_NAME || !CLUSTER_URI) {
|
|
766
786
|
throw new Error(
|
|
767
787
|
`Missing CLUSTER_NAME or CLUSTER_URI in cluster conf: ${JSON.stringify(clusterConf)}`
|
|
768
788
|
);
|
|
769
789
|
}
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
790
|
+
try {
|
|
791
|
+
const connection = mongoose5.createConnection(CLUSTER_URI, this.mongoOptions);
|
|
792
|
+
this.clusterConnections[CLUSTER_NAME] = connection;
|
|
793
|
+
if (!optional) {
|
|
794
|
+
this.initiateConnectionEventListeners(CLUSTER_NAME);
|
|
795
|
+
} else {
|
|
796
|
+
this.initiateOptionalConnectionEventListeners(CLUSTER_NAME);
|
|
797
|
+
}
|
|
798
|
+
await new Promise((resolve, reject) => {
|
|
799
|
+
connection.once("open", () => {
|
|
800
|
+
console.log(`Connected to MongoDB: ${CLUSTER_NAME}`);
|
|
801
|
+
resolve();
|
|
802
|
+
});
|
|
803
|
+
connection.once("error", (err) => {
|
|
804
|
+
if (optional) {
|
|
805
|
+
console.warn(`\u26A0\uFE0F Optional cluster ${CLUSTER_NAME} failed to connect: ${err.message}`);
|
|
806
|
+
resolve();
|
|
807
|
+
} else {
|
|
808
|
+
reject(err);
|
|
809
|
+
}
|
|
810
|
+
});
|
|
777
811
|
});
|
|
778
|
-
|
|
779
|
-
|
|
812
|
+
} catch (err) {
|
|
813
|
+
if (optional) {
|
|
814
|
+
console.warn(`\u26A0\uFE0F Optional cluster ${CLUSTER_NAME} failed to connect: ${err.message}`);
|
|
815
|
+
this.failedOptionalClusters.add(CLUSTER_NAME);
|
|
816
|
+
delete this.clusterConnections[CLUSTER_NAME];
|
|
817
|
+
} else {
|
|
818
|
+
throw err;
|
|
819
|
+
}
|
|
820
|
+
}
|
|
780
821
|
})
|
|
781
822
|
);
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
823
|
+
for (const clusterName of this.failedOptionalClusters) {
|
|
824
|
+
delete this.clusterConnections[clusterName];
|
|
825
|
+
}
|
|
826
|
+
const optionalFailedCount = this.failedOptionalClusters.size;
|
|
827
|
+
const connectedCount = Object.keys(this.clusterConnections).length;
|
|
828
|
+
if (optionalFailedCount > 0) {
|
|
829
|
+
console.log(
|
|
830
|
+
`\u{1F389} Connected to ${connectedCount} MongoDB databases (${optionalFailedCount} optional cluster(s) unavailable)`
|
|
831
|
+
);
|
|
832
|
+
} else {
|
|
833
|
+
console.log(
|
|
834
|
+
`\u{1F389} Connected to ${connectedCount} MongoDB databases`
|
|
835
|
+
);
|
|
836
|
+
}
|
|
785
837
|
return this.clusterConnections;
|
|
786
838
|
}
|
|
787
839
|
// Static method to get the full instance
|
|
@@ -818,6 +870,12 @@ var require_MongoConnector = __commonJS({
|
|
|
818
870
|
}
|
|
819
871
|
return _MongoConnector.instance.tenantToClusterMapping;
|
|
820
872
|
}
|
|
873
|
+
static isClusterUnavailable(clusterName) {
|
|
874
|
+
if (!_MongoConnector.instance) {
|
|
875
|
+
throw new Error("MongoConnector not initialized");
|
|
876
|
+
}
|
|
877
|
+
return _MongoConnector.instance.failedOptionalClusters?.has(clusterName) || !_MongoConnector.instance.clusterConnections[clusterName];
|
|
878
|
+
}
|
|
821
879
|
/**
|
|
822
880
|
* Helper function to close clusterConnections object
|
|
823
881
|
*/
|
package/dist/universal.js
CHANGED
|
@@ -634,8 +634,7 @@ var BASE_BULLMQ_CONFIG = {
|
|
|
634
634
|
}
|
|
635
635
|
},
|
|
636
636
|
workerConfig: {
|
|
637
|
-
concurrency:
|
|
638
|
-
// Sequential processing to avoid MongoDB write conflicts
|
|
637
|
+
concurrency: 100,
|
|
639
638
|
lockDuration: 3e5,
|
|
640
639
|
// 5 minutes lock duration since annotation can be slow
|
|
641
640
|
maxStalledCount: 3
|
package/dist/universal.mjs
CHANGED
|
@@ -597,8 +597,7 @@ var BASE_BULLMQ_CONFIG = {
|
|
|
597
597
|
}
|
|
598
598
|
},
|
|
599
599
|
workerConfig: {
|
|
600
|
-
concurrency:
|
|
601
|
-
// Sequential processing to avoid MongoDB write conflicts
|
|
600
|
+
concurrency: 100,
|
|
602
601
|
lockDuration: 3e5,
|
|
603
602
|
// 5 minutes lock duration since annotation can be slow
|
|
604
603
|
maxStalledCount: 3
|