@okf/ootils 1.5.5 → 1.5.6
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/node.d.mts +37 -1
- package/dist/node.d.ts +37 -1
- package/dist/node.js +152 -8
- package/dist/node.mjs +152 -8
- package/package.json +1 -1
package/dist/node.d.mts
CHANGED
|
@@ -516,6 +516,42 @@ declare class WorkerManager {
|
|
|
516
516
|
}[];
|
|
517
517
|
}
|
|
518
518
|
|
|
519
|
+
declare class ProducerManager {
|
|
520
|
+
static instance: null;
|
|
521
|
+
static initialize(producerClasses?: any[]): any;
|
|
522
|
+
static addJob(producerClassName: any, jobName: any, jobData: any, opts?: {}): Promise<any>;
|
|
523
|
+
static addBulkJobs(producerClassName: any, jobs: any): Promise<any>;
|
|
524
|
+
static getStatus(): Promise<any>;
|
|
525
|
+
static shutdown(): Promise<void>;
|
|
526
|
+
constructor(producerClasses?: any[]);
|
|
527
|
+
producerClasses: any[] | undefined;
|
|
528
|
+
activeProducers: Map<any, any> | undefined;
|
|
529
|
+
/**
|
|
530
|
+
* Initialize all producers as singletons
|
|
531
|
+
*/
|
|
532
|
+
initializeAllProducers(): any[];
|
|
533
|
+
/**
|
|
534
|
+
* Get a specific producer instance
|
|
535
|
+
*/
|
|
536
|
+
getProducer(producerClassName: any): any;
|
|
537
|
+
/**
|
|
538
|
+
* Add a job using a specific producer
|
|
539
|
+
*/
|
|
540
|
+
addJob(producerClassName: any, jobData: any, opts?: {}): Promise<any>;
|
|
541
|
+
/**
|
|
542
|
+
* Add bulk jobs using a specific producer
|
|
543
|
+
*/
|
|
544
|
+
addBulkJobs(producerClassName: any, jobs: any): Promise<any>;
|
|
545
|
+
/**
|
|
546
|
+
* Get status of all producers
|
|
547
|
+
*/
|
|
548
|
+
getStatus(): Promise<any[]>;
|
|
549
|
+
/**
|
|
550
|
+
* Gracefully shutdown all producers
|
|
551
|
+
*/
|
|
552
|
+
shutdown(): Promise<void>;
|
|
553
|
+
}
|
|
554
|
+
|
|
519
555
|
declare class BaseProducer {
|
|
520
556
|
constructor(config: any);
|
|
521
557
|
config: any;
|
|
@@ -593,4 +629,4 @@ declare function GET_GLOBAL_BULLMQ_CONFIG({ env, redisCredentials }: {
|
|
|
593
629
|
};
|
|
594
630
|
}): Object;
|
|
595
631
|
|
|
596
|
-
export { AIChatSchema, AnnotationSchema, BaseProducer, BaseWorker, ElasticSearchConnector, GET_GLOBAL_BULLMQ_CONFIG, MongoConnector, PlatformConfigsSchema, TplSchema, WorkerManager, connectToRedis, deleteVal, extractAllBlocksFromTpl, genTagId, getAIChatModelByTenant, getAIConfigs, getAnnotationsModelByTenant, getDbByTenant, getModelByTenant, getPlatformConfigsModelByTenant, getRedisClient, getTpl, getTplModelByTenant, getVal, initializeGlobalConfig, _recursExtractBlocks as recursivelyExtractBlocks, setVal, toArray, updateGlobalConfig };
|
|
632
|
+
export { AIChatSchema, AnnotationSchema, BaseProducer, BaseWorker, ElasticSearchConnector, GET_GLOBAL_BULLMQ_CONFIG, MongoConnector, PlatformConfigsSchema, ProducerManager, TplSchema, WorkerManager, connectToRedis, deleteVal, extractAllBlocksFromTpl, genTagId, getAIChatModelByTenant, getAIConfigs, getAnnotationsModelByTenant, getDbByTenant, getModelByTenant, getPlatformConfigsModelByTenant, getRedisClient, getTpl, getTplModelByTenant, getVal, initializeGlobalConfig, _recursExtractBlocks as recursivelyExtractBlocks, setVal, toArray, updateGlobalConfig };
|
package/dist/node.d.ts
CHANGED
|
@@ -516,6 +516,42 @@ declare class WorkerManager {
|
|
|
516
516
|
}[];
|
|
517
517
|
}
|
|
518
518
|
|
|
519
|
+
declare class ProducerManager {
|
|
520
|
+
static instance: null;
|
|
521
|
+
static initialize(producerClasses?: any[]): any;
|
|
522
|
+
static addJob(producerClassName: any, jobName: any, jobData: any, opts?: {}): Promise<any>;
|
|
523
|
+
static addBulkJobs(producerClassName: any, jobs: any): Promise<any>;
|
|
524
|
+
static getStatus(): Promise<any>;
|
|
525
|
+
static shutdown(): Promise<void>;
|
|
526
|
+
constructor(producerClasses?: any[]);
|
|
527
|
+
producerClasses: any[] | undefined;
|
|
528
|
+
activeProducers: Map<any, any> | undefined;
|
|
529
|
+
/**
|
|
530
|
+
* Initialize all producers as singletons
|
|
531
|
+
*/
|
|
532
|
+
initializeAllProducers(): any[];
|
|
533
|
+
/**
|
|
534
|
+
* Get a specific producer instance
|
|
535
|
+
*/
|
|
536
|
+
getProducer(producerClassName: any): any;
|
|
537
|
+
/**
|
|
538
|
+
* Add a job using a specific producer
|
|
539
|
+
*/
|
|
540
|
+
addJob(producerClassName: any, jobData: any, opts?: {}): Promise<any>;
|
|
541
|
+
/**
|
|
542
|
+
* Add bulk jobs using a specific producer
|
|
543
|
+
*/
|
|
544
|
+
addBulkJobs(producerClassName: any, jobs: any): Promise<any>;
|
|
545
|
+
/**
|
|
546
|
+
* Get status of all producers
|
|
547
|
+
*/
|
|
548
|
+
getStatus(): Promise<any[]>;
|
|
549
|
+
/**
|
|
550
|
+
* Gracefully shutdown all producers
|
|
551
|
+
*/
|
|
552
|
+
shutdown(): Promise<void>;
|
|
553
|
+
}
|
|
554
|
+
|
|
519
555
|
declare class BaseProducer {
|
|
520
556
|
constructor(config: any);
|
|
521
557
|
config: any;
|
|
@@ -593,4 +629,4 @@ declare function GET_GLOBAL_BULLMQ_CONFIG({ env, redisCredentials }: {
|
|
|
593
629
|
};
|
|
594
630
|
}): Object;
|
|
595
631
|
|
|
596
|
-
export { AIChatSchema, AnnotationSchema, BaseProducer, BaseWorker, ElasticSearchConnector, GET_GLOBAL_BULLMQ_CONFIG, MongoConnector, PlatformConfigsSchema, TplSchema, WorkerManager, connectToRedis, deleteVal, extractAllBlocksFromTpl, genTagId, getAIChatModelByTenant, getAIConfigs, getAnnotationsModelByTenant, getDbByTenant, getModelByTenant, getPlatformConfigsModelByTenant, getRedisClient, getTpl, getTplModelByTenant, getVal, initializeGlobalConfig, _recursExtractBlocks as recursivelyExtractBlocks, setVal, toArray, updateGlobalConfig };
|
|
632
|
+
export { AIChatSchema, AnnotationSchema, BaseProducer, BaseWorker, ElasticSearchConnector, GET_GLOBAL_BULLMQ_CONFIG, MongoConnector, PlatformConfigsSchema, ProducerManager, TplSchema, WorkerManager, connectToRedis, deleteVal, extractAllBlocksFromTpl, genTagId, getAIChatModelByTenant, getAIConfigs, getAnnotationsModelByTenant, getDbByTenant, getModelByTenant, getPlatformConfigsModelByTenant, getRedisClient, getTpl, getTplModelByTenant, getVal, initializeGlobalConfig, _recursExtractBlocks as recursivelyExtractBlocks, setVal, toArray, updateGlobalConfig };
|
package/dist/node.js
CHANGED
|
@@ -779,6 +779,145 @@ var require_WorkerManager = __commonJS({
|
|
|
779
779
|
}
|
|
780
780
|
});
|
|
781
781
|
|
|
782
|
+
// src/bullmq/ProducerManager.js
|
|
783
|
+
var require_ProducerManager = __commonJS({
|
|
784
|
+
"src/bullmq/ProducerManager.js"(exports2, module2) {
|
|
785
|
+
"use strict";
|
|
786
|
+
var _ProducerManager = class _ProducerManager {
|
|
787
|
+
constructor(producerClasses = []) {
|
|
788
|
+
if (_ProducerManager.instance) {
|
|
789
|
+
return _ProducerManager.instance;
|
|
790
|
+
}
|
|
791
|
+
this.producerClasses = producerClasses;
|
|
792
|
+
this.activeProducers = /* @__PURE__ */ new Map();
|
|
793
|
+
_ProducerManager.instance = this;
|
|
794
|
+
}
|
|
795
|
+
// Static methods that delegate to singleton instance
|
|
796
|
+
static initialize(producerClasses = []) {
|
|
797
|
+
if (!this.instance) {
|
|
798
|
+
this.instance = new _ProducerManager(producerClasses);
|
|
799
|
+
}
|
|
800
|
+
return this.instance.initializeAllProducers();
|
|
801
|
+
}
|
|
802
|
+
static async addJob(producerClassName, jobName, jobData, opts = {}) {
|
|
803
|
+
if (!this.instance) {
|
|
804
|
+
throw new Error("ProducerManager not initialized. Call ProducerManager.initialize() first.");
|
|
805
|
+
}
|
|
806
|
+
return await this.instance.addJob(producerClassName, jobName, jobData, opts);
|
|
807
|
+
}
|
|
808
|
+
static async addBulkJobs(producerClassName, jobs) {
|
|
809
|
+
if (!this.instance) {
|
|
810
|
+
throw new Error("ProducerManager not initialized. Call ProducerManager.initialize() first.");
|
|
811
|
+
}
|
|
812
|
+
return await this.instance.addBulkJobs(producerClassName, jobs);
|
|
813
|
+
}
|
|
814
|
+
static async getStatus() {
|
|
815
|
+
if (!this.instance) {
|
|
816
|
+
throw new Error("ProducerManager not initialized. Call ProducerManager.initialize() first.");
|
|
817
|
+
}
|
|
818
|
+
return await this.instance.getStatus();
|
|
819
|
+
}
|
|
820
|
+
static async shutdown() {
|
|
821
|
+
if (this.instance) {
|
|
822
|
+
await this.instance.shutdown();
|
|
823
|
+
this.instance = null;
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
/**
|
|
827
|
+
* Initialize all producers as singletons
|
|
828
|
+
*/
|
|
829
|
+
initializeAllProducers() {
|
|
830
|
+
if (this.producerClasses.length === 0) {
|
|
831
|
+
console.log("No producers provided to initialize");
|
|
832
|
+
return [];
|
|
833
|
+
}
|
|
834
|
+
console.log("\u{1F680} Initializing all producers...");
|
|
835
|
+
this.producerClasses.forEach((ProducerClass) => {
|
|
836
|
+
try {
|
|
837
|
+
const producerInstance = new ProducerClass();
|
|
838
|
+
this.activeProducers.set(ProducerClass.name, {
|
|
839
|
+
class: ProducerClass,
|
|
840
|
+
instance: producerInstance
|
|
841
|
+
});
|
|
842
|
+
console.log(`\u2705 Initialized ${ProducerClass.name}`);
|
|
843
|
+
} catch (error) {
|
|
844
|
+
console.error(`\u274C Failed to initialize ${ProducerClass.name}:`, error);
|
|
845
|
+
}
|
|
846
|
+
});
|
|
847
|
+
console.log(`\u{1F389} Successfully initialized ${this.activeProducers.size} producers`);
|
|
848
|
+
return Array.from(this.activeProducers.values());
|
|
849
|
+
}
|
|
850
|
+
/**
|
|
851
|
+
* Get a specific producer instance
|
|
852
|
+
*/
|
|
853
|
+
getProducer(producerClassName) {
|
|
854
|
+
const producer = this.activeProducers.get(producerClassName);
|
|
855
|
+
if (!producer) {
|
|
856
|
+
throw new Error(`Producer ${producerClassName} not found. Make sure it's initialized.`);
|
|
857
|
+
}
|
|
858
|
+
return producer.instance;
|
|
859
|
+
}
|
|
860
|
+
/**
|
|
861
|
+
* Add a job using a specific producer
|
|
862
|
+
*/
|
|
863
|
+
async addJob(producerClassName, jobData, opts = {}) {
|
|
864
|
+
const producer = this.getProducer(producerClassName);
|
|
865
|
+
return await producer.addJobWithName(jobData, opts);
|
|
866
|
+
}
|
|
867
|
+
/**
|
|
868
|
+
* Add bulk jobs using a specific producer
|
|
869
|
+
*/
|
|
870
|
+
async addBulkJobs(producerClassName, jobs) {
|
|
871
|
+
const producer = this.getProducer(producerClassName);
|
|
872
|
+
return await producer.addBulkJobs(jobs);
|
|
873
|
+
}
|
|
874
|
+
/**
|
|
875
|
+
* Get status of all producers
|
|
876
|
+
*/
|
|
877
|
+
async getStatus() {
|
|
878
|
+
const statusPromises = Array.from(this.activeProducers.entries()).map(
|
|
879
|
+
async ([name, { instance }]) => {
|
|
880
|
+
try {
|
|
881
|
+
const status = await instance.getStatus();
|
|
882
|
+
return {
|
|
883
|
+
name,
|
|
884
|
+
queueId: instance.config?.id || "unknown",
|
|
885
|
+
isActive: !!instance.queue,
|
|
886
|
+
...status
|
|
887
|
+
};
|
|
888
|
+
} catch (error) {
|
|
889
|
+
return {
|
|
890
|
+
name,
|
|
891
|
+
queueId: instance.config?.id || "unknown",
|
|
892
|
+
isActive: false,
|
|
893
|
+
error: error.message
|
|
894
|
+
};
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
);
|
|
898
|
+
return await Promise.all(statusPromises);
|
|
899
|
+
}
|
|
900
|
+
/**
|
|
901
|
+
* Gracefully shutdown all producers
|
|
902
|
+
*/
|
|
903
|
+
async shutdown() {
|
|
904
|
+
console.log("\u{1F6D1} Stopping all producers...");
|
|
905
|
+
const stopPromises = Array.from(this.activeProducers.entries()).map(
|
|
906
|
+
([name, { instance }]) => instance.stop().catch(
|
|
907
|
+
(err) => console.error(`\u274C Error stopping ${name}:`, err)
|
|
908
|
+
)
|
|
909
|
+
);
|
|
910
|
+
await Promise.all(stopPromises);
|
|
911
|
+
this.activeProducers.clear();
|
|
912
|
+
console.log("\u2705 All producers stopped");
|
|
913
|
+
}
|
|
914
|
+
};
|
|
915
|
+
__publicField(_ProducerManager, "instance", null);
|
|
916
|
+
var ProducerManager2 = _ProducerManager;
|
|
917
|
+
module2.exports = { ProducerManager: ProducerManager2 };
|
|
918
|
+
}
|
|
919
|
+
});
|
|
920
|
+
|
|
782
921
|
// src/bullmq/BaseProducer.js
|
|
783
922
|
var require_BaseProducer = __commonJS({
|
|
784
923
|
"src/bullmq/BaseProducer.js"(exports2, module2) {
|
|
@@ -861,7 +1000,8 @@ var require_BaseProducer = __commonJS({
|
|
|
861
1000
|
async stop() {
|
|
862
1001
|
if (this.queue) {
|
|
863
1002
|
await this.queue.close();
|
|
864
|
-
|
|
1003
|
+
await this.queue.disconnect();
|
|
1004
|
+
console.log(`\u{1F6D1} ${this.constructor.name} queue closed & disconnected`);
|
|
865
1005
|
}
|
|
866
1006
|
}
|
|
867
1007
|
};
|
|
@@ -921,7 +1061,8 @@ var require_BaseWorker = __commonJS({
|
|
|
921
1061
|
async stop() {
|
|
922
1062
|
if (this.worker) {
|
|
923
1063
|
await this.worker.close();
|
|
924
|
-
|
|
1064
|
+
await this.worker.disconnect();
|
|
1065
|
+
console.log(`\u{1F6D1} ${this.constructor.name} stopped & disconnected`);
|
|
925
1066
|
}
|
|
926
1067
|
}
|
|
927
1068
|
};
|
|
@@ -956,7 +1097,7 @@ var init_GLOBAL_BULLMQ_CONFIG = __esm({
|
|
|
956
1097
|
concurrency: 1,
|
|
957
1098
|
// Process jobs one at a time to avoid race conditions
|
|
958
1099
|
limiter: {
|
|
959
|
-
max:
|
|
1100
|
+
max: 5,
|
|
960
1101
|
// Max 10 jobs per...
|
|
961
1102
|
duration: 6e4
|
|
962
1103
|
// ...60 seconds (rate limiting)
|
|
@@ -1028,7 +1169,7 @@ var init_GLOBAL_BULLMQ_CONFIG = __esm({
|
|
|
1028
1169
|
workerConfig: {
|
|
1029
1170
|
concurrency: 1,
|
|
1030
1171
|
limiter: {
|
|
1031
|
-
max:
|
|
1172
|
+
max: 15,
|
|
1032
1173
|
// Max 50 jobs per...
|
|
1033
1174
|
duration: 6e4
|
|
1034
1175
|
// ...60 seconds (higher throughput for chunking)
|
|
@@ -1074,8 +1215,8 @@ var init_GLOBAL_BULLMQ_CONFIG = __esm({
|
|
|
1074
1215
|
workerConfig: {
|
|
1075
1216
|
concurrency: 1,
|
|
1076
1217
|
limiter: {
|
|
1077
|
-
max:
|
|
1078
|
-
//
|
|
1218
|
+
max: 15,
|
|
1219
|
+
// (lets always keep this same as content enhance & embed since it comes immediately after)
|
|
1079
1220
|
duration: 6e4
|
|
1080
1221
|
// ...60 seconds (higher throughput for chunking)
|
|
1081
1222
|
}
|
|
@@ -1097,8 +1238,8 @@ var init_GLOBAL_BULLMQ_CONFIG = __esm({
|
|
|
1097
1238
|
workerConfig: {
|
|
1098
1239
|
concurrency: 5,
|
|
1099
1240
|
limiter: {
|
|
1100
|
-
max:
|
|
1101
|
-
//
|
|
1241
|
+
max: 15,
|
|
1242
|
+
// (lets always keep this same as content enhance & embed since it comes immediately after)
|
|
1102
1243
|
duration: 6e4
|
|
1103
1244
|
// ...60 seconds (higher throughput for chunking)
|
|
1104
1245
|
}
|
|
@@ -1153,6 +1294,7 @@ __export(node_exports, {
|
|
|
1153
1294
|
GET_GLOBAL_BULLMQ_CONFIG: () => import_GET_GLOBAL_BULLMQ_CONFIG.GET_GLOBAL_BULLMQ_CONFIG,
|
|
1154
1295
|
MongoConnector: () => import_MongoConnector2.MongoConnector,
|
|
1155
1296
|
PlatformConfigsSchema: () => PlatformConfigs_default,
|
|
1297
|
+
ProducerManager: () => import_ProducerManager.ProducerManager,
|
|
1156
1298
|
TplSchema: () => Tpl_default,
|
|
1157
1299
|
WorkerManager: () => import_WorkerManager.WorkerManager,
|
|
1158
1300
|
connectToRedis: () => connectToRedis,
|
|
@@ -1594,6 +1736,7 @@ var getAIConfigs = async ({
|
|
|
1594
1736
|
// src/node.ts
|
|
1595
1737
|
init_models();
|
|
1596
1738
|
var import_WorkerManager = __toESM(require_WorkerManager());
|
|
1739
|
+
var import_ProducerManager = __toESM(require_ProducerManager());
|
|
1597
1740
|
var import_BaseProducer = __toESM(require_BaseProducer());
|
|
1598
1741
|
var import_BaseWorker = __toESM(require_BaseWorker());
|
|
1599
1742
|
var import_GET_GLOBAL_BULLMQ_CONFIG = __toESM(require_GET_GLOBAL_BULLMQ_CONFIG());
|
|
@@ -1607,6 +1750,7 @@ var import_GET_GLOBAL_BULLMQ_CONFIG = __toESM(require_GET_GLOBAL_BULLMQ_CONFIG()
|
|
|
1607
1750
|
GET_GLOBAL_BULLMQ_CONFIG,
|
|
1608
1751
|
MongoConnector,
|
|
1609
1752
|
PlatformConfigsSchema,
|
|
1753
|
+
ProducerManager,
|
|
1610
1754
|
TplSchema,
|
|
1611
1755
|
WorkerManager,
|
|
1612
1756
|
connectToRedis,
|
package/dist/node.mjs
CHANGED
|
@@ -784,6 +784,145 @@ var require_WorkerManager = __commonJS({
|
|
|
784
784
|
}
|
|
785
785
|
});
|
|
786
786
|
|
|
787
|
+
// src/bullmq/ProducerManager.js
|
|
788
|
+
var require_ProducerManager = __commonJS({
|
|
789
|
+
"src/bullmq/ProducerManager.js"(exports, module) {
|
|
790
|
+
"use strict";
|
|
791
|
+
var _ProducerManager = class _ProducerManager {
|
|
792
|
+
constructor(producerClasses = []) {
|
|
793
|
+
if (_ProducerManager.instance) {
|
|
794
|
+
return _ProducerManager.instance;
|
|
795
|
+
}
|
|
796
|
+
this.producerClasses = producerClasses;
|
|
797
|
+
this.activeProducers = /* @__PURE__ */ new Map();
|
|
798
|
+
_ProducerManager.instance = this;
|
|
799
|
+
}
|
|
800
|
+
// Static methods that delegate to singleton instance
|
|
801
|
+
static initialize(producerClasses = []) {
|
|
802
|
+
if (!this.instance) {
|
|
803
|
+
this.instance = new _ProducerManager(producerClasses);
|
|
804
|
+
}
|
|
805
|
+
return this.instance.initializeAllProducers();
|
|
806
|
+
}
|
|
807
|
+
static async addJob(producerClassName, jobName, jobData, opts = {}) {
|
|
808
|
+
if (!this.instance) {
|
|
809
|
+
throw new Error("ProducerManager not initialized. Call ProducerManager.initialize() first.");
|
|
810
|
+
}
|
|
811
|
+
return await this.instance.addJob(producerClassName, jobName, jobData, opts);
|
|
812
|
+
}
|
|
813
|
+
static async addBulkJobs(producerClassName, jobs) {
|
|
814
|
+
if (!this.instance) {
|
|
815
|
+
throw new Error("ProducerManager not initialized. Call ProducerManager.initialize() first.");
|
|
816
|
+
}
|
|
817
|
+
return await this.instance.addBulkJobs(producerClassName, jobs);
|
|
818
|
+
}
|
|
819
|
+
static async getStatus() {
|
|
820
|
+
if (!this.instance) {
|
|
821
|
+
throw new Error("ProducerManager not initialized. Call ProducerManager.initialize() first.");
|
|
822
|
+
}
|
|
823
|
+
return await this.instance.getStatus();
|
|
824
|
+
}
|
|
825
|
+
static async shutdown() {
|
|
826
|
+
if (this.instance) {
|
|
827
|
+
await this.instance.shutdown();
|
|
828
|
+
this.instance = null;
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
/**
|
|
832
|
+
* Initialize all producers as singletons
|
|
833
|
+
*/
|
|
834
|
+
initializeAllProducers() {
|
|
835
|
+
if (this.producerClasses.length === 0) {
|
|
836
|
+
console.log("No producers provided to initialize");
|
|
837
|
+
return [];
|
|
838
|
+
}
|
|
839
|
+
console.log("\u{1F680} Initializing all producers...");
|
|
840
|
+
this.producerClasses.forEach((ProducerClass) => {
|
|
841
|
+
try {
|
|
842
|
+
const producerInstance = new ProducerClass();
|
|
843
|
+
this.activeProducers.set(ProducerClass.name, {
|
|
844
|
+
class: ProducerClass,
|
|
845
|
+
instance: producerInstance
|
|
846
|
+
});
|
|
847
|
+
console.log(`\u2705 Initialized ${ProducerClass.name}`);
|
|
848
|
+
} catch (error) {
|
|
849
|
+
console.error(`\u274C Failed to initialize ${ProducerClass.name}:`, error);
|
|
850
|
+
}
|
|
851
|
+
});
|
|
852
|
+
console.log(`\u{1F389} Successfully initialized ${this.activeProducers.size} producers`);
|
|
853
|
+
return Array.from(this.activeProducers.values());
|
|
854
|
+
}
|
|
855
|
+
/**
|
|
856
|
+
* Get a specific producer instance
|
|
857
|
+
*/
|
|
858
|
+
getProducer(producerClassName) {
|
|
859
|
+
const producer = this.activeProducers.get(producerClassName);
|
|
860
|
+
if (!producer) {
|
|
861
|
+
throw new Error(`Producer ${producerClassName} not found. Make sure it's initialized.`);
|
|
862
|
+
}
|
|
863
|
+
return producer.instance;
|
|
864
|
+
}
|
|
865
|
+
/**
|
|
866
|
+
* Add a job using a specific producer
|
|
867
|
+
*/
|
|
868
|
+
async addJob(producerClassName, jobData, opts = {}) {
|
|
869
|
+
const producer = this.getProducer(producerClassName);
|
|
870
|
+
return await producer.addJobWithName(jobData, opts);
|
|
871
|
+
}
|
|
872
|
+
/**
|
|
873
|
+
* Add bulk jobs using a specific producer
|
|
874
|
+
*/
|
|
875
|
+
async addBulkJobs(producerClassName, jobs) {
|
|
876
|
+
const producer = this.getProducer(producerClassName);
|
|
877
|
+
return await producer.addBulkJobs(jobs);
|
|
878
|
+
}
|
|
879
|
+
/**
|
|
880
|
+
* Get status of all producers
|
|
881
|
+
*/
|
|
882
|
+
async getStatus() {
|
|
883
|
+
const statusPromises = Array.from(this.activeProducers.entries()).map(
|
|
884
|
+
async ([name, { instance }]) => {
|
|
885
|
+
try {
|
|
886
|
+
const status = await instance.getStatus();
|
|
887
|
+
return {
|
|
888
|
+
name,
|
|
889
|
+
queueId: instance.config?.id || "unknown",
|
|
890
|
+
isActive: !!instance.queue,
|
|
891
|
+
...status
|
|
892
|
+
};
|
|
893
|
+
} catch (error) {
|
|
894
|
+
return {
|
|
895
|
+
name,
|
|
896
|
+
queueId: instance.config?.id || "unknown",
|
|
897
|
+
isActive: false,
|
|
898
|
+
error: error.message
|
|
899
|
+
};
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
);
|
|
903
|
+
return await Promise.all(statusPromises);
|
|
904
|
+
}
|
|
905
|
+
/**
|
|
906
|
+
* Gracefully shutdown all producers
|
|
907
|
+
*/
|
|
908
|
+
async shutdown() {
|
|
909
|
+
console.log("\u{1F6D1} Stopping all producers...");
|
|
910
|
+
const stopPromises = Array.from(this.activeProducers.entries()).map(
|
|
911
|
+
([name, { instance }]) => instance.stop().catch(
|
|
912
|
+
(err) => console.error(`\u274C Error stopping ${name}:`, err)
|
|
913
|
+
)
|
|
914
|
+
);
|
|
915
|
+
await Promise.all(stopPromises);
|
|
916
|
+
this.activeProducers.clear();
|
|
917
|
+
console.log("\u2705 All producers stopped");
|
|
918
|
+
}
|
|
919
|
+
};
|
|
920
|
+
__publicField(_ProducerManager, "instance", null);
|
|
921
|
+
var ProducerManager2 = _ProducerManager;
|
|
922
|
+
module.exports = { ProducerManager: ProducerManager2 };
|
|
923
|
+
}
|
|
924
|
+
});
|
|
925
|
+
|
|
787
926
|
// src/bullmq/BaseProducer.js
|
|
788
927
|
var require_BaseProducer = __commonJS({
|
|
789
928
|
"src/bullmq/BaseProducer.js"(exports, module) {
|
|
@@ -866,7 +1005,8 @@ var require_BaseProducer = __commonJS({
|
|
|
866
1005
|
async stop() {
|
|
867
1006
|
if (this.queue) {
|
|
868
1007
|
await this.queue.close();
|
|
869
|
-
|
|
1008
|
+
await this.queue.disconnect();
|
|
1009
|
+
console.log(`\u{1F6D1} ${this.constructor.name} queue closed & disconnected`);
|
|
870
1010
|
}
|
|
871
1011
|
}
|
|
872
1012
|
};
|
|
@@ -926,7 +1066,8 @@ var require_BaseWorker = __commonJS({
|
|
|
926
1066
|
async stop() {
|
|
927
1067
|
if (this.worker) {
|
|
928
1068
|
await this.worker.close();
|
|
929
|
-
|
|
1069
|
+
await this.worker.disconnect();
|
|
1070
|
+
console.log(`\u{1F6D1} ${this.constructor.name} stopped & disconnected`);
|
|
930
1071
|
}
|
|
931
1072
|
}
|
|
932
1073
|
};
|
|
@@ -961,7 +1102,7 @@ var init_GLOBAL_BULLMQ_CONFIG = __esm({
|
|
|
961
1102
|
concurrency: 1,
|
|
962
1103
|
// Process jobs one at a time to avoid race conditions
|
|
963
1104
|
limiter: {
|
|
964
|
-
max:
|
|
1105
|
+
max: 5,
|
|
965
1106
|
// Max 10 jobs per...
|
|
966
1107
|
duration: 6e4
|
|
967
1108
|
// ...60 seconds (rate limiting)
|
|
@@ -1033,7 +1174,7 @@ var init_GLOBAL_BULLMQ_CONFIG = __esm({
|
|
|
1033
1174
|
workerConfig: {
|
|
1034
1175
|
concurrency: 1,
|
|
1035
1176
|
limiter: {
|
|
1036
|
-
max:
|
|
1177
|
+
max: 15,
|
|
1037
1178
|
// Max 50 jobs per...
|
|
1038
1179
|
duration: 6e4
|
|
1039
1180
|
// ...60 seconds (higher throughput for chunking)
|
|
@@ -1079,8 +1220,8 @@ var init_GLOBAL_BULLMQ_CONFIG = __esm({
|
|
|
1079
1220
|
workerConfig: {
|
|
1080
1221
|
concurrency: 1,
|
|
1081
1222
|
limiter: {
|
|
1082
|
-
max:
|
|
1083
|
-
//
|
|
1223
|
+
max: 15,
|
|
1224
|
+
// (lets always keep this same as content enhance & embed since it comes immediately after)
|
|
1084
1225
|
duration: 6e4
|
|
1085
1226
|
// ...60 seconds (higher throughput for chunking)
|
|
1086
1227
|
}
|
|
@@ -1102,8 +1243,8 @@ var init_GLOBAL_BULLMQ_CONFIG = __esm({
|
|
|
1102
1243
|
workerConfig: {
|
|
1103
1244
|
concurrency: 5,
|
|
1104
1245
|
limiter: {
|
|
1105
|
-
max:
|
|
1106
|
-
//
|
|
1246
|
+
max: 15,
|
|
1247
|
+
// (lets always keep this same as content enhance & embed since it comes immediately after)
|
|
1107
1248
|
duration: 6e4
|
|
1108
1249
|
// ...60 seconds (higher throughput for chunking)
|
|
1109
1250
|
}
|
|
@@ -1564,6 +1705,7 @@ var getAIConfigs = async ({
|
|
|
1564
1705
|
// src/node.ts
|
|
1565
1706
|
init_models();
|
|
1566
1707
|
var import_WorkerManager = __toESM(require_WorkerManager());
|
|
1708
|
+
var import_ProducerManager = __toESM(require_ProducerManager());
|
|
1567
1709
|
var import_BaseProducer = __toESM(require_BaseProducer());
|
|
1568
1710
|
var import_BaseWorker = __toESM(require_BaseWorker());
|
|
1569
1711
|
var import_GET_GLOBAL_BULLMQ_CONFIG = __toESM(require_GET_GLOBAL_BULLMQ_CONFIG());
|
|
@@ -1572,6 +1714,7 @@ var export_BaseWorker = import_BaseWorker.BaseWorker;
|
|
|
1572
1714
|
var export_ElasticSearchConnector = import_ElasticSearchConnector.ElasticSearchConnector;
|
|
1573
1715
|
var export_GET_GLOBAL_BULLMQ_CONFIG = import_GET_GLOBAL_BULLMQ_CONFIG.GET_GLOBAL_BULLMQ_CONFIG;
|
|
1574
1716
|
var export_MongoConnector = import_MongoConnector2.MongoConnector;
|
|
1717
|
+
var export_ProducerManager = import_ProducerManager.ProducerManager;
|
|
1575
1718
|
var export_WorkerManager = import_WorkerManager.WorkerManager;
|
|
1576
1719
|
var export_getAIChatModelByTenant = import_getModelByTenant.getAIChatModelByTenant;
|
|
1577
1720
|
var export_getAnnotationsModelByTenant = import_getModelByTenant.getAnnotationsModelByTenant;
|
|
@@ -1587,6 +1730,7 @@ export {
|
|
|
1587
1730
|
export_GET_GLOBAL_BULLMQ_CONFIG as GET_GLOBAL_BULLMQ_CONFIG,
|
|
1588
1731
|
export_MongoConnector as MongoConnector,
|
|
1589
1732
|
PlatformConfigs_default as PlatformConfigsSchema,
|
|
1733
|
+
export_ProducerManager as ProducerManager,
|
|
1590
1734
|
Tpl_default as TplSchema,
|
|
1591
1735
|
export_WorkerManager as WorkerManager,
|
|
1592
1736
|
connectToRedis,
|