@okf/ootils 1.3.7 → 1.3.9
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 +99 -1
- package/dist/node.d.ts +99 -1
- package/dist/node.js +329 -0
- package/dist/node.mjs +362 -0
- package/package.json +2 -1
package/dist/node.d.mts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import mongoose, { Connection, Document, Schema, Model, Types } from 'mongoose';
|
|
2
2
|
import IORedis from 'ioredis';
|
|
3
|
+
import * as bullmq from 'bullmq';
|
|
4
|
+
import { Queue } from 'bullmq/dist/esm/classes/queue';
|
|
5
|
+
import { Worker } from 'bullmq/dist/esm/classes/worker';
|
|
3
6
|
|
|
4
7
|
declare const deleteVal: (data: any, valuePath: string) => any;
|
|
5
8
|
|
|
@@ -250,6 +253,11 @@ declare const getAnnotationsModelByTenant: ({ tenant, env, mongodb, dbConfigs, m
|
|
|
250
253
|
}> & {
|
|
251
254
|
__v: number;
|
|
252
255
|
}, any>;
|
|
256
|
+
declare const getChunksModelByTenant: ({ tenant, env, mongodb, dbConfigs, modelName }: GetModelShortParams) => Model<Document<unknown, any, any, Record<string, any>>, {}, {}, {}, Document<unknown, {}, Document<unknown, any, any, Record<string, any>>, {}> & Document<unknown, any, any, Record<string, any>> & Required<{
|
|
257
|
+
_id: unknown;
|
|
258
|
+
}> & {
|
|
259
|
+
__v: number;
|
|
260
|
+
}, any>;
|
|
253
261
|
declare const getPlatformConfigsModelByTenant: ({ tenant, env, mongodb, dbConfigs }: GetModelShortParams) => Model<Document<unknown, any, any, Record<string, any>>, {}, {}, {}, Document<unknown, {}, Document<unknown, any, any, Record<string, any>>, {}> & Document<unknown, any, any, Record<string, any>> & Required<{
|
|
254
262
|
_id: unknown;
|
|
255
263
|
}> & {
|
|
@@ -496,4 +504,94 @@ declare const TplSchema: mongoose.Schema<ITplDocument, mongoose.Model<ITplDocume
|
|
|
496
504
|
__v: number;
|
|
497
505
|
}>;
|
|
498
506
|
|
|
499
|
-
|
|
507
|
+
declare class WorkerManager {
|
|
508
|
+
constructor(workers?: any[]);
|
|
509
|
+
workers: any[];
|
|
510
|
+
activeWorkers: any[];
|
|
511
|
+
startAllWorkers(): any[];
|
|
512
|
+
shutdown(): Promise<void>;
|
|
513
|
+
getStatus(): {
|
|
514
|
+
name: any;
|
|
515
|
+
queueId: any;
|
|
516
|
+
isActive: boolean;
|
|
517
|
+
}[];
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
declare class BaseProducer {
|
|
521
|
+
constructor(config: any);
|
|
522
|
+
config: any;
|
|
523
|
+
queue: Queue<any, any, string, any, any, string>;
|
|
524
|
+
execute(params: any): Promise<void>;
|
|
525
|
+
addBulkJobs(jobs: any): Promise<bullmq.Job<any, any, string>[]>;
|
|
526
|
+
addJob(name: any, data: any, opts?: {}): Promise<bullmq.Job<any, any, string>>;
|
|
527
|
+
getStatus(): Promise<{
|
|
528
|
+
waiting: number;
|
|
529
|
+
active: number;
|
|
530
|
+
completed: number;
|
|
531
|
+
failed: number;
|
|
532
|
+
total: number;
|
|
533
|
+
}>;
|
|
534
|
+
getJobDetails(limit?: number): Promise<{
|
|
535
|
+
waiting: {
|
|
536
|
+
id: any;
|
|
537
|
+
batchIndex: any;
|
|
538
|
+
totalBatches: any;
|
|
539
|
+
rawRecordsCount: any;
|
|
540
|
+
}[];
|
|
541
|
+
active: {
|
|
542
|
+
id: any;
|
|
543
|
+
batchIndex: any;
|
|
544
|
+
totalBatches: any;
|
|
545
|
+
progress: any;
|
|
546
|
+
rawRecordsCount: any;
|
|
547
|
+
}[];
|
|
548
|
+
completed: {
|
|
549
|
+
id: any;
|
|
550
|
+
batchIndex: any;
|
|
551
|
+
totalProcessed: any;
|
|
552
|
+
summary: any;
|
|
553
|
+
}[];
|
|
554
|
+
failed: {
|
|
555
|
+
id: any;
|
|
556
|
+
batchIndex: any;
|
|
557
|
+
error: any;
|
|
558
|
+
attempts: any;
|
|
559
|
+
}[];
|
|
560
|
+
}>;
|
|
561
|
+
stop(): Promise<void>;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
declare class BaseWorker {
|
|
565
|
+
constructor(config: any);
|
|
566
|
+
config: any;
|
|
567
|
+
worker: Worker<any, void, string> | null;
|
|
568
|
+
execute(job: any): Promise<void>;
|
|
569
|
+
start(): Worker<any, void, string>;
|
|
570
|
+
setupEventHandlers(): void;
|
|
571
|
+
onCompleted(job: any, returnValue: any): void;
|
|
572
|
+
onFailed(job: any, err: any): void;
|
|
573
|
+
onProgress(job: any, progress: any): void;
|
|
574
|
+
onError(error: any): void;
|
|
575
|
+
stop(): Promise<void>;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* Creates BullMQ configuration with explicit dependencies
|
|
580
|
+
* @param {Object} params Configuration parameters
|
|
581
|
+
* @param {string} params.env Environment (staging, production, etc.)
|
|
582
|
+
* @param {Object} params.redisCredentials Redis connection details
|
|
583
|
+
* @param {string} params.redisCredentials.REDIS_HOST Redis host
|
|
584
|
+
* @param {number} params.redisCredentials.REDIS_PORT Redis port
|
|
585
|
+
* @param {string} params.redisCredentials.REDIS_PASSWORD Redis password
|
|
586
|
+
* @returns {Object} Complete BullMQ configuration
|
|
587
|
+
*/
|
|
588
|
+
declare function GET_GLOBAL_BULLMQ_CONFIG({ env, redisCredentials }: {
|
|
589
|
+
env: string;
|
|
590
|
+
redisCredentials: {
|
|
591
|
+
REDIS_HOST: string;
|
|
592
|
+
REDIS_PORT: number;
|
|
593
|
+
REDIS_PASSWORD: string;
|
|
594
|
+
};
|
|
595
|
+
}): Object;
|
|
596
|
+
|
|
597
|
+
export { AIChatSchema, AnnotationSchema, BaseProducer, BaseWorker, GET_GLOBAL_BULLMQ_CONFIG, PlatformConfigsSchema, TplSchema, WorkerManager, connectToRedis, deleteVal, extractAllBlocksFromTpl, genTagId, getAIChatModelByTenant, getAIConfigs, getAnnotationsModelByTenant, getChunksModelByTenant, getDbByTenant, getModelByTenant, getPlatformConfigsModelByTenant, getRedisClient, getTpl, getTplModelByTenant, getVal, initializeGlobalConfig, multiConnectToMongoDB, _recursExtractBlocks as recursivelyExtractBlocks, setVal, toArray, updateGlobalConfig };
|
package/dist/node.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import mongoose, { Connection, Document, Schema, Model, Types } from 'mongoose';
|
|
2
2
|
import IORedis from 'ioredis';
|
|
3
|
+
import * as bullmq from 'bullmq';
|
|
4
|
+
import { Queue } from 'bullmq/dist/esm/classes/queue';
|
|
5
|
+
import { Worker } from 'bullmq/dist/esm/classes/worker';
|
|
3
6
|
|
|
4
7
|
declare const deleteVal: (data: any, valuePath: string) => any;
|
|
5
8
|
|
|
@@ -250,6 +253,11 @@ declare const getAnnotationsModelByTenant: ({ tenant, env, mongodb, dbConfigs, m
|
|
|
250
253
|
}> & {
|
|
251
254
|
__v: number;
|
|
252
255
|
}, any>;
|
|
256
|
+
declare const getChunksModelByTenant: ({ tenant, env, mongodb, dbConfigs, modelName }: GetModelShortParams) => Model<Document<unknown, any, any, Record<string, any>>, {}, {}, {}, Document<unknown, {}, Document<unknown, any, any, Record<string, any>>, {}> & Document<unknown, any, any, Record<string, any>> & Required<{
|
|
257
|
+
_id: unknown;
|
|
258
|
+
}> & {
|
|
259
|
+
__v: number;
|
|
260
|
+
}, any>;
|
|
253
261
|
declare const getPlatformConfigsModelByTenant: ({ tenant, env, mongodb, dbConfigs }: GetModelShortParams) => Model<Document<unknown, any, any, Record<string, any>>, {}, {}, {}, Document<unknown, {}, Document<unknown, any, any, Record<string, any>>, {}> & Document<unknown, any, any, Record<string, any>> & Required<{
|
|
254
262
|
_id: unknown;
|
|
255
263
|
}> & {
|
|
@@ -496,4 +504,94 @@ declare const TplSchema: mongoose.Schema<ITplDocument, mongoose.Model<ITplDocume
|
|
|
496
504
|
__v: number;
|
|
497
505
|
}>;
|
|
498
506
|
|
|
499
|
-
|
|
507
|
+
declare class WorkerManager {
|
|
508
|
+
constructor(workers?: any[]);
|
|
509
|
+
workers: any[];
|
|
510
|
+
activeWorkers: any[];
|
|
511
|
+
startAllWorkers(): any[];
|
|
512
|
+
shutdown(): Promise<void>;
|
|
513
|
+
getStatus(): {
|
|
514
|
+
name: any;
|
|
515
|
+
queueId: any;
|
|
516
|
+
isActive: boolean;
|
|
517
|
+
}[];
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
declare class BaseProducer {
|
|
521
|
+
constructor(config: any);
|
|
522
|
+
config: any;
|
|
523
|
+
queue: Queue<any, any, string, any, any, string>;
|
|
524
|
+
execute(params: any): Promise<void>;
|
|
525
|
+
addBulkJobs(jobs: any): Promise<bullmq.Job<any, any, string>[]>;
|
|
526
|
+
addJob(name: any, data: any, opts?: {}): Promise<bullmq.Job<any, any, string>>;
|
|
527
|
+
getStatus(): Promise<{
|
|
528
|
+
waiting: number;
|
|
529
|
+
active: number;
|
|
530
|
+
completed: number;
|
|
531
|
+
failed: number;
|
|
532
|
+
total: number;
|
|
533
|
+
}>;
|
|
534
|
+
getJobDetails(limit?: number): Promise<{
|
|
535
|
+
waiting: {
|
|
536
|
+
id: any;
|
|
537
|
+
batchIndex: any;
|
|
538
|
+
totalBatches: any;
|
|
539
|
+
rawRecordsCount: any;
|
|
540
|
+
}[];
|
|
541
|
+
active: {
|
|
542
|
+
id: any;
|
|
543
|
+
batchIndex: any;
|
|
544
|
+
totalBatches: any;
|
|
545
|
+
progress: any;
|
|
546
|
+
rawRecordsCount: any;
|
|
547
|
+
}[];
|
|
548
|
+
completed: {
|
|
549
|
+
id: any;
|
|
550
|
+
batchIndex: any;
|
|
551
|
+
totalProcessed: any;
|
|
552
|
+
summary: any;
|
|
553
|
+
}[];
|
|
554
|
+
failed: {
|
|
555
|
+
id: any;
|
|
556
|
+
batchIndex: any;
|
|
557
|
+
error: any;
|
|
558
|
+
attempts: any;
|
|
559
|
+
}[];
|
|
560
|
+
}>;
|
|
561
|
+
stop(): Promise<void>;
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
declare class BaseWorker {
|
|
565
|
+
constructor(config: any);
|
|
566
|
+
config: any;
|
|
567
|
+
worker: Worker<any, void, string> | null;
|
|
568
|
+
execute(job: any): Promise<void>;
|
|
569
|
+
start(): Worker<any, void, string>;
|
|
570
|
+
setupEventHandlers(): void;
|
|
571
|
+
onCompleted(job: any, returnValue: any): void;
|
|
572
|
+
onFailed(job: any, err: any): void;
|
|
573
|
+
onProgress(job: any, progress: any): void;
|
|
574
|
+
onError(error: any): void;
|
|
575
|
+
stop(): Promise<void>;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
/**
|
|
579
|
+
* Creates BullMQ configuration with explicit dependencies
|
|
580
|
+
* @param {Object} params Configuration parameters
|
|
581
|
+
* @param {string} params.env Environment (staging, production, etc.)
|
|
582
|
+
* @param {Object} params.redisCredentials Redis connection details
|
|
583
|
+
* @param {string} params.redisCredentials.REDIS_HOST Redis host
|
|
584
|
+
* @param {number} params.redisCredentials.REDIS_PORT Redis port
|
|
585
|
+
* @param {string} params.redisCredentials.REDIS_PASSWORD Redis password
|
|
586
|
+
* @returns {Object} Complete BullMQ configuration
|
|
587
|
+
*/
|
|
588
|
+
declare function GET_GLOBAL_BULLMQ_CONFIG({ env, redisCredentials }: {
|
|
589
|
+
env: string;
|
|
590
|
+
redisCredentials: {
|
|
591
|
+
REDIS_HOST: string;
|
|
592
|
+
REDIS_PORT: number;
|
|
593
|
+
REDIS_PASSWORD: string;
|
|
594
|
+
};
|
|
595
|
+
}): Object;
|
|
596
|
+
|
|
597
|
+
export { AIChatSchema, AnnotationSchema, BaseProducer, BaseWorker, GET_GLOBAL_BULLMQ_CONFIG, PlatformConfigsSchema, TplSchema, WorkerManager, connectToRedis, deleteVal, extractAllBlocksFromTpl, genTagId, getAIChatModelByTenant, getAIConfigs, getAnnotationsModelByTenant, getChunksModelByTenant, getDbByTenant, getModelByTenant, getPlatformConfigsModelByTenant, getRedisClient, getTpl, getTplModelByTenant, getVal, initializeGlobalConfig, multiConnectToMongoDB, _recursExtractBlocks as recursivelyExtractBlocks, setVal, toArray, updateGlobalConfig };
|
package/dist/node.js
CHANGED
|
@@ -5,6 +5,12 @@ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
|
5
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __esm = (fn, res) => function __init() {
|
|
9
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
10
|
+
};
|
|
11
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
12
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
13
|
+
};
|
|
8
14
|
var __export = (target, all) => {
|
|
9
15
|
for (var name in all)
|
|
10
16
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -27,13 +33,318 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
33
|
));
|
|
28
34
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
35
|
|
|
36
|
+
// src/bullmq/WorkerManager.js
|
|
37
|
+
var require_WorkerManager = __commonJS({
|
|
38
|
+
"src/bullmq/WorkerManager.js"(exports2, module2) {
|
|
39
|
+
"use strict";
|
|
40
|
+
var WorkerManager2 = class {
|
|
41
|
+
constructor(workers = []) {
|
|
42
|
+
this.workers = workers;
|
|
43
|
+
this.activeWorkers = [];
|
|
44
|
+
}
|
|
45
|
+
startAllWorkers() {
|
|
46
|
+
if (this.workers.length === 0) {
|
|
47
|
+
console.log("No workers provided to start");
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
50
|
+
console.log("\u{1F680} Starting all workers...");
|
|
51
|
+
this.workers.forEach((WorkerClass) => {
|
|
52
|
+
try {
|
|
53
|
+
const workerInstance = new WorkerClass();
|
|
54
|
+
workerInstance.start();
|
|
55
|
+
this.activeWorkers.push({
|
|
56
|
+
name: WorkerClass.name,
|
|
57
|
+
instance: workerInstance
|
|
58
|
+
});
|
|
59
|
+
console.log(`\u2705 Started ${WorkerClass.name}`);
|
|
60
|
+
} catch (error) {
|
|
61
|
+
console.error(`\u274C Failed to start ${WorkerClass.name}:`, error);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
console.log(`\u{1F389} Successfully started ${this.activeWorkers.length} workers`);
|
|
65
|
+
return this.activeWorkers;
|
|
66
|
+
}
|
|
67
|
+
async shutdown() {
|
|
68
|
+
console.log("\u{1F6D1} Stopping all workers...");
|
|
69
|
+
const stopPromises = this.activeWorkers.map(
|
|
70
|
+
({ name, instance }) => instance.stop().catch(
|
|
71
|
+
(err) => console.error(`\u274C Error stopping ${name}:`, err)
|
|
72
|
+
)
|
|
73
|
+
);
|
|
74
|
+
await Promise.all(stopPromises);
|
|
75
|
+
this.activeWorkers = [];
|
|
76
|
+
console.log("\u2705 All workers stopped");
|
|
77
|
+
}
|
|
78
|
+
getStatus() {
|
|
79
|
+
return this.activeWorkers.map(({ name, instance }) => ({
|
|
80
|
+
name,
|
|
81
|
+
queueId: instance.config?.id || "unknown",
|
|
82
|
+
isActive: !!instance.worker
|
|
83
|
+
}));
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
module2.exports = { WorkerManager: WorkerManager2 };
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// src/bullmq/BaseProducer.js
|
|
91
|
+
var require_BaseProducer = __commonJS({
|
|
92
|
+
"src/bullmq/BaseProducer.js"(exports2, module2) {
|
|
93
|
+
"use strict";
|
|
94
|
+
var { Queue } = require("bullmq");
|
|
95
|
+
var BaseProducer2 = class {
|
|
96
|
+
constructor(config) {
|
|
97
|
+
this.config = config;
|
|
98
|
+
this.queue = new Queue(config.id, config.queueConfig);
|
|
99
|
+
}
|
|
100
|
+
async execute(params) {
|
|
101
|
+
throw new Error("execute() method must be implemented by subclass");
|
|
102
|
+
}
|
|
103
|
+
async addBulkJobs(jobs) {
|
|
104
|
+
try {
|
|
105
|
+
const results = await this.queue.addBulk(jobs);
|
|
106
|
+
console.log(`\u2705 ${this.constructor.name}: Successfully queued ${results.length} jobs`);
|
|
107
|
+
return results;
|
|
108
|
+
} catch (error) {
|
|
109
|
+
console.error(`\u274C ${this.constructor.name}: Failed to queue jobs:`, error);
|
|
110
|
+
throw error;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
async addJob(name, data, opts = {}) {
|
|
114
|
+
try {
|
|
115
|
+
const job = await this.queue.add(name, data, opts);
|
|
116
|
+
console.log(`\u2705 ${this.constructor.name}: Successfully queued job ${job.id}`);
|
|
117
|
+
return job;
|
|
118
|
+
} catch (error) {
|
|
119
|
+
console.error(`\u274C ${this.constructor.name}: Failed to queue job:`, error);
|
|
120
|
+
throw error;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
async getStatus() {
|
|
124
|
+
const waiting = await this.queue.getWaiting();
|
|
125
|
+
const active = await this.queue.getActive();
|
|
126
|
+
const completed = await this.queue.getCompleted();
|
|
127
|
+
const failed = await this.queue.getFailed();
|
|
128
|
+
return {
|
|
129
|
+
waiting: waiting.length,
|
|
130
|
+
active: active.length,
|
|
131
|
+
completed: completed.length,
|
|
132
|
+
failed: failed.length,
|
|
133
|
+
total: waiting.length + active.length + completed.length + failed.length
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
async getJobDetails(limit = 10) {
|
|
137
|
+
const waiting = await this.queue.getWaiting(0, limit - 1);
|
|
138
|
+
const active = await this.queue.getActive(0, limit - 1);
|
|
139
|
+
const completed = await this.queue.getCompleted(0, limit - 1);
|
|
140
|
+
const failed = await this.queue.getFailed(0, limit - 1);
|
|
141
|
+
return {
|
|
142
|
+
waiting: waiting.map((job) => ({
|
|
143
|
+
id: job.id,
|
|
144
|
+
batchIndex: job.data?.batchIndex,
|
|
145
|
+
totalBatches: job.data?.totalBatches,
|
|
146
|
+
rawRecordsCount: job.data?.rawBatchData?.length
|
|
147
|
+
})),
|
|
148
|
+
active: active.map((job) => ({
|
|
149
|
+
id: job.id,
|
|
150
|
+
batchIndex: job.data?.batchIndex,
|
|
151
|
+
totalBatches: job.data?.totalBatches,
|
|
152
|
+
progress: job.progress,
|
|
153
|
+
rawRecordsCount: job.data?.rawBatchData?.length
|
|
154
|
+
})),
|
|
155
|
+
completed: completed.map((job) => ({
|
|
156
|
+
id: job.id,
|
|
157
|
+
batchIndex: job.returnvalue?.batchIndex,
|
|
158
|
+
totalProcessed: job.returnvalue?.totalItemsProcessed,
|
|
159
|
+
summary: job.returnvalue?.summary
|
|
160
|
+
})),
|
|
161
|
+
failed: failed.map((job) => ({
|
|
162
|
+
id: job.id,
|
|
163
|
+
batchIndex: job.data?.batchIndex,
|
|
164
|
+
error: job.failedReason,
|
|
165
|
+
attempts: job.attemptsMade
|
|
166
|
+
}))
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
async stop() {
|
|
170
|
+
if (this.queue) {
|
|
171
|
+
await this.queue.close();
|
|
172
|
+
console.log(`\u{1F6D1} ${this.constructor.name} queue closed`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
module2.exports = { BaseProducer: BaseProducer2 };
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
// src/bullmq/BaseWorker.js
|
|
181
|
+
var require_BaseWorker = __commonJS({
|
|
182
|
+
"src/bullmq/BaseWorker.js"(exports2, module2) {
|
|
183
|
+
"use strict";
|
|
184
|
+
var { Worker } = require("bullmq");
|
|
185
|
+
var BaseWorker2 = class {
|
|
186
|
+
constructor(config) {
|
|
187
|
+
this.config = config;
|
|
188
|
+
this.worker = null;
|
|
189
|
+
}
|
|
190
|
+
async execute(job) {
|
|
191
|
+
throw new Error("execute() method must be implemented by subclass");
|
|
192
|
+
}
|
|
193
|
+
start() {
|
|
194
|
+
this.worker = new Worker(
|
|
195
|
+
this.config.id,
|
|
196
|
+
this.execute.bind(this),
|
|
197
|
+
this.config.workerConfig
|
|
198
|
+
);
|
|
199
|
+
this.setupEventHandlers();
|
|
200
|
+
console.log(`\u{1F680} ${this.constructor.name} started for queue: ${this.config.id}`);
|
|
201
|
+
return this.worker;
|
|
202
|
+
}
|
|
203
|
+
setupEventHandlers() {
|
|
204
|
+
this.worker.on("completed", (job, returnValue) => {
|
|
205
|
+
this.onCompleted(job, returnValue);
|
|
206
|
+
});
|
|
207
|
+
this.worker.on("failed", (job, err) => {
|
|
208
|
+
this.onFailed(job, err);
|
|
209
|
+
});
|
|
210
|
+
this.worker.on("progress", (job, progress) => {
|
|
211
|
+
this.onProgress(job, progress);
|
|
212
|
+
});
|
|
213
|
+
this.worker.on("error", (error) => {
|
|
214
|
+
this.onError(error);
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
onCompleted(job, returnValue) {
|
|
218
|
+
console.log(`\u2705 Job ${job.id} completed in ${this.constructor.name}`);
|
|
219
|
+
}
|
|
220
|
+
onFailed(job, err) {
|
|
221
|
+
console.error(`\u{1F4A5} Job ${job.id} failed in ${this.constructor.name}:`, err.message);
|
|
222
|
+
}
|
|
223
|
+
onProgress(job, progress) {
|
|
224
|
+
console.log(`\u{1F4CA} Job ${job.id} progress in ${this.constructor.name}: ${progress}%`);
|
|
225
|
+
}
|
|
226
|
+
onError(error) {
|
|
227
|
+
console.error(`\u274C Worker error in ${this.constructor.name}:`, error);
|
|
228
|
+
}
|
|
229
|
+
async stop() {
|
|
230
|
+
if (this.worker) {
|
|
231
|
+
await this.worker.close();
|
|
232
|
+
console.log(`\u{1F6D1} ${this.constructor.name} stopped`);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
module2.exports = { BaseWorker: BaseWorker2 };
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
// src/bullmq/GLOBAL_BULLMQ_CONFIG.js
|
|
241
|
+
var GLOBAL_BULLMQ_CONFIG_exports = {};
|
|
242
|
+
__export(GLOBAL_BULLMQ_CONFIG_exports, {
|
|
243
|
+
BASE_BULLMQ_CONFIG: () => BASE_BULLMQ_CONFIG
|
|
244
|
+
});
|
|
245
|
+
var BASE_BULLMQ_CONFIG;
|
|
246
|
+
var init_GLOBAL_BULLMQ_CONFIG = __esm({
|
|
247
|
+
"src/bullmq/GLOBAL_BULLMQ_CONFIG.js"() {
|
|
248
|
+
"use strict";
|
|
249
|
+
BASE_BULLMQ_CONFIG = {
|
|
250
|
+
PLUGIN__MAD_USERS_SYNC_QUEUE: {
|
|
251
|
+
id: "plugin--mad-users-sync-queue",
|
|
252
|
+
queueConfig: {
|
|
253
|
+
defaultJobOptions: {
|
|
254
|
+
backoff: {
|
|
255
|
+
type: "exponential",
|
|
256
|
+
delay: 2e3
|
|
257
|
+
},
|
|
258
|
+
attempts: 3,
|
|
259
|
+
removeOnComplete: 100,
|
|
260
|
+
removeOnFail: 50
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
workerConfig: {
|
|
264
|
+
concurrency: 1,
|
|
265
|
+
// Process jobs one at a time to avoid race conditions
|
|
266
|
+
limiter: {
|
|
267
|
+
max: 10,
|
|
268
|
+
// Max 10 jobs per...
|
|
269
|
+
duration: 6e4
|
|
270
|
+
// ...60 seconds (rate limiting)
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
},
|
|
274
|
+
// Chunk Processing Queue
|
|
275
|
+
CHUNK_PROCESSING_QUEUE: {
|
|
276
|
+
id: "chunk-processing-queue",
|
|
277
|
+
queueConfig: {
|
|
278
|
+
defaultJobOptions: {
|
|
279
|
+
backoff: {
|
|
280
|
+
type: "exponential",
|
|
281
|
+
delay: 2e3
|
|
282
|
+
},
|
|
283
|
+
attempts: 3,
|
|
284
|
+
removeOnComplete: 100,
|
|
285
|
+
removeOnFail: 50
|
|
286
|
+
}
|
|
287
|
+
},
|
|
288
|
+
workerConfig: {
|
|
289
|
+
concurrency: 10,
|
|
290
|
+
// Process 10 jobs at once for chunk processing
|
|
291
|
+
limiter: {
|
|
292
|
+
max: 5,
|
|
293
|
+
// Max 50 jobs per...
|
|
294
|
+
duration: 6e4
|
|
295
|
+
// ...60 seconds (higher throughput for chunking)
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
// src/bullmq/GET_GLOBAL_BULLMQ_CONFIG.js
|
|
304
|
+
var require_GET_GLOBAL_BULLMQ_CONFIG = __commonJS({
|
|
305
|
+
"src/bullmq/GET_GLOBAL_BULLMQ_CONFIG.js"(exports2, module2) {
|
|
306
|
+
"use strict";
|
|
307
|
+
var { default: Redis } = require("ioredis");
|
|
308
|
+
var { BASE_BULLMQ_CONFIG: BASE_BULLMQ_CONFIG2 } = (init_GLOBAL_BULLMQ_CONFIG(), __toCommonJS(GLOBAL_BULLMQ_CONFIG_exports));
|
|
309
|
+
function GET_GLOBAL_BULLMQ_CONFIG2({ env, redisCredentials }) {
|
|
310
|
+
const redisConnectionForBullMQ = new Redis({
|
|
311
|
+
host: redisCredentials.REDIS_HOST,
|
|
312
|
+
port: redisCredentials.REDIS_PORT,
|
|
313
|
+
password: redisCredentials.REDIS_PASSWORD,
|
|
314
|
+
maxRetriesPerRequest: null
|
|
315
|
+
});
|
|
316
|
+
return Object.keys(BASE_BULLMQ_CONFIG2).reduce((acc, key) => ({
|
|
317
|
+
...acc,
|
|
318
|
+
[key]: {
|
|
319
|
+
...BASE_BULLMQ_CONFIG2[key],
|
|
320
|
+
id: BASE_BULLMQ_CONFIG2[key].id + `_${env}`,
|
|
321
|
+
// suffix env to queue to keep it unique for each environment
|
|
322
|
+
queueConfig: {
|
|
323
|
+
connection: redisConnectionForBullMQ,
|
|
324
|
+
...BASE_BULLMQ_CONFIG2[key].queueConfig
|
|
325
|
+
},
|
|
326
|
+
workerConfig: {
|
|
327
|
+
connection: redisConnectionForBullMQ,
|
|
328
|
+
...BASE_BULLMQ_CONFIG2[key].workerConfig
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}), {});
|
|
332
|
+
}
|
|
333
|
+
module2.exports = { GET_GLOBAL_BULLMQ_CONFIG: GET_GLOBAL_BULLMQ_CONFIG2 };
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
|
|
30
337
|
// src/node.ts
|
|
31
338
|
var node_exports = {};
|
|
32
339
|
__export(node_exports, {
|
|
33
340
|
AIChatSchema: () => AIChat_default,
|
|
34
341
|
AnnotationSchema: () => Annotations_default,
|
|
342
|
+
BaseProducer: () => import_BaseProducer.BaseProducer,
|
|
343
|
+
BaseWorker: () => import_BaseWorker.BaseWorker,
|
|
344
|
+
GET_GLOBAL_BULLMQ_CONFIG: () => import_GET_GLOBAL_BULLMQ_CONFIG.GET_GLOBAL_BULLMQ_CONFIG,
|
|
35
345
|
PlatformConfigsSchema: () => PlatformConfigs_default,
|
|
36
346
|
TplSchema: () => Tpl_default,
|
|
347
|
+
WorkerManager: () => import_WorkerManager.WorkerManager,
|
|
37
348
|
connectToRedis: () => connectToRedis,
|
|
38
349
|
deleteVal: () => deleteVal,
|
|
39
350
|
extractAllBlocksFromTpl: () => extractAllBlocksFromTpl,
|
|
@@ -41,6 +352,7 @@ __export(node_exports, {
|
|
|
41
352
|
getAIChatModelByTenant: () => getAIChatModelByTenant,
|
|
42
353
|
getAIConfigs: () => getAIConfigs,
|
|
43
354
|
getAnnotationsModelByTenant: () => getAnnotationsModelByTenant,
|
|
355
|
+
getChunksModelByTenant: () => getChunksModelByTenant,
|
|
44
356
|
getDbByTenant: () => getDbByTenant,
|
|
45
357
|
getModelByTenant: () => getModelByTenant,
|
|
46
358
|
getPlatformConfigsModelByTenant: () => getPlatformConfigsModelByTenant,
|
|
@@ -762,6 +1074,12 @@ var getAnnotationsModelByTenant = ({ tenant, env, mongodb, dbConfigs, modelName
|
|
|
762
1074
|
schema: Annotations_default,
|
|
763
1075
|
env
|
|
764
1076
|
});
|
|
1077
|
+
var getChunksModelByTenant = ({ tenant, env, mongodb, dbConfigs, modelName }) => getModelByTenant({
|
|
1078
|
+
tenant,
|
|
1079
|
+
modelName: modelName || "chunks",
|
|
1080
|
+
schema: Annotations_default,
|
|
1081
|
+
env
|
|
1082
|
+
});
|
|
765
1083
|
var getPlatformConfigsModelByTenant = ({ tenant, env, mongodb, dbConfigs }) => getModelByTenant({
|
|
766
1084
|
tenant,
|
|
767
1085
|
modelName: "platformConfigs",
|
|
@@ -887,12 +1205,22 @@ var getAIConfigs = async ({
|
|
|
887
1205
|
}
|
|
888
1206
|
});
|
|
889
1207
|
};
|
|
1208
|
+
|
|
1209
|
+
// src/node.ts
|
|
1210
|
+
var import_WorkerManager = __toESM(require_WorkerManager());
|
|
1211
|
+
var import_BaseProducer = __toESM(require_BaseProducer());
|
|
1212
|
+
var import_BaseWorker = __toESM(require_BaseWorker());
|
|
1213
|
+
var import_GET_GLOBAL_BULLMQ_CONFIG = __toESM(require_GET_GLOBAL_BULLMQ_CONFIG());
|
|
890
1214
|
// Annotate the CommonJS export names for ESM import in node:
|
|
891
1215
|
0 && (module.exports = {
|
|
892
1216
|
AIChatSchema,
|
|
893
1217
|
AnnotationSchema,
|
|
1218
|
+
BaseProducer,
|
|
1219
|
+
BaseWorker,
|
|
1220
|
+
GET_GLOBAL_BULLMQ_CONFIG,
|
|
894
1221
|
PlatformConfigsSchema,
|
|
895
1222
|
TplSchema,
|
|
1223
|
+
WorkerManager,
|
|
896
1224
|
connectToRedis,
|
|
897
1225
|
deleteVal,
|
|
898
1226
|
extractAllBlocksFromTpl,
|
|
@@ -900,6 +1228,7 @@ var getAIConfigs = async ({
|
|
|
900
1228
|
getAIChatModelByTenant,
|
|
901
1229
|
getAIConfigs,
|
|
902
1230
|
getAnnotationsModelByTenant,
|
|
1231
|
+
getChunksModelByTenant,
|
|
903
1232
|
getDbByTenant,
|
|
904
1233
|
getModelByTenant,
|
|
905
1234
|
getPlatformConfigsModelByTenant,
|
package/dist/node.mjs
CHANGED
|
@@ -1,3 +1,344 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
8
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
9
|
+
}) : x)(function(x) {
|
|
10
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
11
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
12
|
+
});
|
|
13
|
+
var __esm = (fn, res) => function __init() {
|
|
14
|
+
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
15
|
+
};
|
|
16
|
+
var __commonJS = (cb, mod) => function __require2() {
|
|
17
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
18
|
+
};
|
|
19
|
+
var __export = (target, all) => {
|
|
20
|
+
for (var name in all)
|
|
21
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
22
|
+
};
|
|
23
|
+
var __copyProps = (to, from, except, desc) => {
|
|
24
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
25
|
+
for (let key of __getOwnPropNames(from))
|
|
26
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
27
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
28
|
+
}
|
|
29
|
+
return to;
|
|
30
|
+
};
|
|
31
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
32
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
33
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
34
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
35
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
36
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
37
|
+
mod
|
|
38
|
+
));
|
|
39
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
40
|
+
|
|
41
|
+
// src/bullmq/WorkerManager.js
|
|
42
|
+
var require_WorkerManager = __commonJS({
|
|
43
|
+
"src/bullmq/WorkerManager.js"(exports, module) {
|
|
44
|
+
"use strict";
|
|
45
|
+
var WorkerManager2 = class {
|
|
46
|
+
constructor(workers = []) {
|
|
47
|
+
this.workers = workers;
|
|
48
|
+
this.activeWorkers = [];
|
|
49
|
+
}
|
|
50
|
+
startAllWorkers() {
|
|
51
|
+
if (this.workers.length === 0) {
|
|
52
|
+
console.log("No workers provided to start");
|
|
53
|
+
return [];
|
|
54
|
+
}
|
|
55
|
+
console.log("\u{1F680} Starting all workers...");
|
|
56
|
+
this.workers.forEach((WorkerClass) => {
|
|
57
|
+
try {
|
|
58
|
+
const workerInstance = new WorkerClass();
|
|
59
|
+
workerInstance.start();
|
|
60
|
+
this.activeWorkers.push({
|
|
61
|
+
name: WorkerClass.name,
|
|
62
|
+
instance: workerInstance
|
|
63
|
+
});
|
|
64
|
+
console.log(`\u2705 Started ${WorkerClass.name}`);
|
|
65
|
+
} catch (error) {
|
|
66
|
+
console.error(`\u274C Failed to start ${WorkerClass.name}:`, error);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
console.log(`\u{1F389} Successfully started ${this.activeWorkers.length} workers`);
|
|
70
|
+
return this.activeWorkers;
|
|
71
|
+
}
|
|
72
|
+
async shutdown() {
|
|
73
|
+
console.log("\u{1F6D1} Stopping all workers...");
|
|
74
|
+
const stopPromises = this.activeWorkers.map(
|
|
75
|
+
({ name, instance }) => instance.stop().catch(
|
|
76
|
+
(err) => console.error(`\u274C Error stopping ${name}:`, err)
|
|
77
|
+
)
|
|
78
|
+
);
|
|
79
|
+
await Promise.all(stopPromises);
|
|
80
|
+
this.activeWorkers = [];
|
|
81
|
+
console.log("\u2705 All workers stopped");
|
|
82
|
+
}
|
|
83
|
+
getStatus() {
|
|
84
|
+
return this.activeWorkers.map(({ name, instance }) => ({
|
|
85
|
+
name,
|
|
86
|
+
queueId: instance.config?.id || "unknown",
|
|
87
|
+
isActive: !!instance.worker
|
|
88
|
+
}));
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
module.exports = { WorkerManager: WorkerManager2 };
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// src/bullmq/BaseProducer.js
|
|
96
|
+
var require_BaseProducer = __commonJS({
|
|
97
|
+
"src/bullmq/BaseProducer.js"(exports, module) {
|
|
98
|
+
"use strict";
|
|
99
|
+
var { Queue } = __require("bullmq");
|
|
100
|
+
var BaseProducer2 = class {
|
|
101
|
+
constructor(config) {
|
|
102
|
+
this.config = config;
|
|
103
|
+
this.queue = new Queue(config.id, config.queueConfig);
|
|
104
|
+
}
|
|
105
|
+
async execute(params) {
|
|
106
|
+
throw new Error("execute() method must be implemented by subclass");
|
|
107
|
+
}
|
|
108
|
+
async addBulkJobs(jobs) {
|
|
109
|
+
try {
|
|
110
|
+
const results = await this.queue.addBulk(jobs);
|
|
111
|
+
console.log(`\u2705 ${this.constructor.name}: Successfully queued ${results.length} jobs`);
|
|
112
|
+
return results;
|
|
113
|
+
} catch (error) {
|
|
114
|
+
console.error(`\u274C ${this.constructor.name}: Failed to queue jobs:`, error);
|
|
115
|
+
throw error;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
async addJob(name, data, opts = {}) {
|
|
119
|
+
try {
|
|
120
|
+
const job = await this.queue.add(name, data, opts);
|
|
121
|
+
console.log(`\u2705 ${this.constructor.name}: Successfully queued job ${job.id}`);
|
|
122
|
+
return job;
|
|
123
|
+
} catch (error) {
|
|
124
|
+
console.error(`\u274C ${this.constructor.name}: Failed to queue job:`, error);
|
|
125
|
+
throw error;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
async getStatus() {
|
|
129
|
+
const waiting = await this.queue.getWaiting();
|
|
130
|
+
const active = await this.queue.getActive();
|
|
131
|
+
const completed = await this.queue.getCompleted();
|
|
132
|
+
const failed = await this.queue.getFailed();
|
|
133
|
+
return {
|
|
134
|
+
waiting: waiting.length,
|
|
135
|
+
active: active.length,
|
|
136
|
+
completed: completed.length,
|
|
137
|
+
failed: failed.length,
|
|
138
|
+
total: waiting.length + active.length + completed.length + failed.length
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
async getJobDetails(limit = 10) {
|
|
142
|
+
const waiting = await this.queue.getWaiting(0, limit - 1);
|
|
143
|
+
const active = await this.queue.getActive(0, limit - 1);
|
|
144
|
+
const completed = await this.queue.getCompleted(0, limit - 1);
|
|
145
|
+
const failed = await this.queue.getFailed(0, limit - 1);
|
|
146
|
+
return {
|
|
147
|
+
waiting: waiting.map((job) => ({
|
|
148
|
+
id: job.id,
|
|
149
|
+
batchIndex: job.data?.batchIndex,
|
|
150
|
+
totalBatches: job.data?.totalBatches,
|
|
151
|
+
rawRecordsCount: job.data?.rawBatchData?.length
|
|
152
|
+
})),
|
|
153
|
+
active: active.map((job) => ({
|
|
154
|
+
id: job.id,
|
|
155
|
+
batchIndex: job.data?.batchIndex,
|
|
156
|
+
totalBatches: job.data?.totalBatches,
|
|
157
|
+
progress: job.progress,
|
|
158
|
+
rawRecordsCount: job.data?.rawBatchData?.length
|
|
159
|
+
})),
|
|
160
|
+
completed: completed.map((job) => ({
|
|
161
|
+
id: job.id,
|
|
162
|
+
batchIndex: job.returnvalue?.batchIndex,
|
|
163
|
+
totalProcessed: job.returnvalue?.totalItemsProcessed,
|
|
164
|
+
summary: job.returnvalue?.summary
|
|
165
|
+
})),
|
|
166
|
+
failed: failed.map((job) => ({
|
|
167
|
+
id: job.id,
|
|
168
|
+
batchIndex: job.data?.batchIndex,
|
|
169
|
+
error: job.failedReason,
|
|
170
|
+
attempts: job.attemptsMade
|
|
171
|
+
}))
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
async stop() {
|
|
175
|
+
if (this.queue) {
|
|
176
|
+
await this.queue.close();
|
|
177
|
+
console.log(`\u{1F6D1} ${this.constructor.name} queue closed`);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
};
|
|
181
|
+
module.exports = { BaseProducer: BaseProducer2 };
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
// src/bullmq/BaseWorker.js
|
|
186
|
+
var require_BaseWorker = __commonJS({
|
|
187
|
+
"src/bullmq/BaseWorker.js"(exports, module) {
|
|
188
|
+
"use strict";
|
|
189
|
+
var { Worker } = __require("bullmq");
|
|
190
|
+
var BaseWorker2 = class {
|
|
191
|
+
constructor(config) {
|
|
192
|
+
this.config = config;
|
|
193
|
+
this.worker = null;
|
|
194
|
+
}
|
|
195
|
+
async execute(job) {
|
|
196
|
+
throw new Error("execute() method must be implemented by subclass");
|
|
197
|
+
}
|
|
198
|
+
start() {
|
|
199
|
+
this.worker = new Worker(
|
|
200
|
+
this.config.id,
|
|
201
|
+
this.execute.bind(this),
|
|
202
|
+
this.config.workerConfig
|
|
203
|
+
);
|
|
204
|
+
this.setupEventHandlers();
|
|
205
|
+
console.log(`\u{1F680} ${this.constructor.name} started for queue: ${this.config.id}`);
|
|
206
|
+
return this.worker;
|
|
207
|
+
}
|
|
208
|
+
setupEventHandlers() {
|
|
209
|
+
this.worker.on("completed", (job, returnValue) => {
|
|
210
|
+
this.onCompleted(job, returnValue);
|
|
211
|
+
});
|
|
212
|
+
this.worker.on("failed", (job, err) => {
|
|
213
|
+
this.onFailed(job, err);
|
|
214
|
+
});
|
|
215
|
+
this.worker.on("progress", (job, progress) => {
|
|
216
|
+
this.onProgress(job, progress);
|
|
217
|
+
});
|
|
218
|
+
this.worker.on("error", (error) => {
|
|
219
|
+
this.onError(error);
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
onCompleted(job, returnValue) {
|
|
223
|
+
console.log(`\u2705 Job ${job.id} completed in ${this.constructor.name}`);
|
|
224
|
+
}
|
|
225
|
+
onFailed(job, err) {
|
|
226
|
+
console.error(`\u{1F4A5} Job ${job.id} failed in ${this.constructor.name}:`, err.message);
|
|
227
|
+
}
|
|
228
|
+
onProgress(job, progress) {
|
|
229
|
+
console.log(`\u{1F4CA} Job ${job.id} progress in ${this.constructor.name}: ${progress}%`);
|
|
230
|
+
}
|
|
231
|
+
onError(error) {
|
|
232
|
+
console.error(`\u274C Worker error in ${this.constructor.name}:`, error);
|
|
233
|
+
}
|
|
234
|
+
async stop() {
|
|
235
|
+
if (this.worker) {
|
|
236
|
+
await this.worker.close();
|
|
237
|
+
console.log(`\u{1F6D1} ${this.constructor.name} stopped`);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
module.exports = { BaseWorker: BaseWorker2 };
|
|
242
|
+
}
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
// src/bullmq/GLOBAL_BULLMQ_CONFIG.js
|
|
246
|
+
var GLOBAL_BULLMQ_CONFIG_exports = {};
|
|
247
|
+
__export(GLOBAL_BULLMQ_CONFIG_exports, {
|
|
248
|
+
BASE_BULLMQ_CONFIG: () => BASE_BULLMQ_CONFIG
|
|
249
|
+
});
|
|
250
|
+
var BASE_BULLMQ_CONFIG;
|
|
251
|
+
var init_GLOBAL_BULLMQ_CONFIG = __esm({
|
|
252
|
+
"src/bullmq/GLOBAL_BULLMQ_CONFIG.js"() {
|
|
253
|
+
"use strict";
|
|
254
|
+
BASE_BULLMQ_CONFIG = {
|
|
255
|
+
PLUGIN__MAD_USERS_SYNC_QUEUE: {
|
|
256
|
+
id: "plugin--mad-users-sync-queue",
|
|
257
|
+
queueConfig: {
|
|
258
|
+
defaultJobOptions: {
|
|
259
|
+
backoff: {
|
|
260
|
+
type: "exponential",
|
|
261
|
+
delay: 2e3
|
|
262
|
+
},
|
|
263
|
+
attempts: 3,
|
|
264
|
+
removeOnComplete: 100,
|
|
265
|
+
removeOnFail: 50
|
|
266
|
+
}
|
|
267
|
+
},
|
|
268
|
+
workerConfig: {
|
|
269
|
+
concurrency: 1,
|
|
270
|
+
// Process jobs one at a time to avoid race conditions
|
|
271
|
+
limiter: {
|
|
272
|
+
max: 10,
|
|
273
|
+
// Max 10 jobs per...
|
|
274
|
+
duration: 6e4
|
|
275
|
+
// ...60 seconds (rate limiting)
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
},
|
|
279
|
+
// Chunk Processing Queue
|
|
280
|
+
CHUNK_PROCESSING_QUEUE: {
|
|
281
|
+
id: "chunk-processing-queue",
|
|
282
|
+
queueConfig: {
|
|
283
|
+
defaultJobOptions: {
|
|
284
|
+
backoff: {
|
|
285
|
+
type: "exponential",
|
|
286
|
+
delay: 2e3
|
|
287
|
+
},
|
|
288
|
+
attempts: 3,
|
|
289
|
+
removeOnComplete: 100,
|
|
290
|
+
removeOnFail: 50
|
|
291
|
+
}
|
|
292
|
+
},
|
|
293
|
+
workerConfig: {
|
|
294
|
+
concurrency: 10,
|
|
295
|
+
// Process 10 jobs at once for chunk processing
|
|
296
|
+
limiter: {
|
|
297
|
+
max: 5,
|
|
298
|
+
// Max 50 jobs per...
|
|
299
|
+
duration: 6e4
|
|
300
|
+
// ...60 seconds (higher throughput for chunking)
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
// src/bullmq/GET_GLOBAL_BULLMQ_CONFIG.js
|
|
309
|
+
var require_GET_GLOBAL_BULLMQ_CONFIG = __commonJS({
|
|
310
|
+
"src/bullmq/GET_GLOBAL_BULLMQ_CONFIG.js"(exports, module) {
|
|
311
|
+
"use strict";
|
|
312
|
+
var { default: Redis } = __require("ioredis");
|
|
313
|
+
var { BASE_BULLMQ_CONFIG: BASE_BULLMQ_CONFIG2 } = (init_GLOBAL_BULLMQ_CONFIG(), __toCommonJS(GLOBAL_BULLMQ_CONFIG_exports));
|
|
314
|
+
function GET_GLOBAL_BULLMQ_CONFIG2({ env, redisCredentials }) {
|
|
315
|
+
const redisConnectionForBullMQ = new Redis({
|
|
316
|
+
host: redisCredentials.REDIS_HOST,
|
|
317
|
+
port: redisCredentials.REDIS_PORT,
|
|
318
|
+
password: redisCredentials.REDIS_PASSWORD,
|
|
319
|
+
maxRetriesPerRequest: null
|
|
320
|
+
});
|
|
321
|
+
return Object.keys(BASE_BULLMQ_CONFIG2).reduce((acc, key) => ({
|
|
322
|
+
...acc,
|
|
323
|
+
[key]: {
|
|
324
|
+
...BASE_BULLMQ_CONFIG2[key],
|
|
325
|
+
id: BASE_BULLMQ_CONFIG2[key].id + `_${env}`,
|
|
326
|
+
// suffix env to queue to keep it unique for each environment
|
|
327
|
+
queueConfig: {
|
|
328
|
+
connection: redisConnectionForBullMQ,
|
|
329
|
+
...BASE_BULLMQ_CONFIG2[key].queueConfig
|
|
330
|
+
},
|
|
331
|
+
workerConfig: {
|
|
332
|
+
connection: redisConnectionForBullMQ,
|
|
333
|
+
...BASE_BULLMQ_CONFIG2[key].workerConfig
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}), {});
|
|
337
|
+
}
|
|
338
|
+
module.exports = { GET_GLOBAL_BULLMQ_CONFIG: GET_GLOBAL_BULLMQ_CONFIG2 };
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
|
|
1
342
|
// src/utils/getterSetterDeleter/utils/set_deleteVal.ts
|
|
2
343
|
var set_deleteVal = (action, data, valuePath, value) => {
|
|
3
344
|
if (valuePath === void 0) return;
|
|
@@ -703,6 +1044,12 @@ var getAnnotationsModelByTenant = ({ tenant, env, mongodb, dbConfigs, modelName
|
|
|
703
1044
|
schema: Annotations_default,
|
|
704
1045
|
env
|
|
705
1046
|
});
|
|
1047
|
+
var getChunksModelByTenant = ({ tenant, env, mongodb, dbConfigs, modelName }) => getModelByTenant({
|
|
1048
|
+
tenant,
|
|
1049
|
+
modelName: modelName || "chunks",
|
|
1050
|
+
schema: Annotations_default,
|
|
1051
|
+
env
|
|
1052
|
+
});
|
|
706
1053
|
var getPlatformConfigsModelByTenant = ({ tenant, env, mongodb, dbConfigs }) => getModelByTenant({
|
|
707
1054
|
tenant,
|
|
708
1055
|
modelName: "platformConfigs",
|
|
@@ -828,11 +1175,25 @@ var getAIConfigs = async ({
|
|
|
828
1175
|
}
|
|
829
1176
|
});
|
|
830
1177
|
};
|
|
1178
|
+
|
|
1179
|
+
// src/node.ts
|
|
1180
|
+
var import_WorkerManager = __toESM(require_WorkerManager());
|
|
1181
|
+
var import_BaseProducer = __toESM(require_BaseProducer());
|
|
1182
|
+
var import_BaseWorker = __toESM(require_BaseWorker());
|
|
1183
|
+
var import_GET_GLOBAL_BULLMQ_CONFIG = __toESM(require_GET_GLOBAL_BULLMQ_CONFIG());
|
|
1184
|
+
var export_BaseProducer = import_BaseProducer.BaseProducer;
|
|
1185
|
+
var export_BaseWorker = import_BaseWorker.BaseWorker;
|
|
1186
|
+
var export_GET_GLOBAL_BULLMQ_CONFIG = import_GET_GLOBAL_BULLMQ_CONFIG.GET_GLOBAL_BULLMQ_CONFIG;
|
|
1187
|
+
var export_WorkerManager = import_WorkerManager.WorkerManager;
|
|
831
1188
|
export {
|
|
832
1189
|
AIChat_default as AIChatSchema,
|
|
833
1190
|
Annotations_default as AnnotationSchema,
|
|
1191
|
+
export_BaseProducer as BaseProducer,
|
|
1192
|
+
export_BaseWorker as BaseWorker,
|
|
1193
|
+
export_GET_GLOBAL_BULLMQ_CONFIG as GET_GLOBAL_BULLMQ_CONFIG,
|
|
834
1194
|
PlatformConfigs_default as PlatformConfigsSchema,
|
|
835
1195
|
Tpl_default as TplSchema,
|
|
1196
|
+
export_WorkerManager as WorkerManager,
|
|
836
1197
|
connectToRedis,
|
|
837
1198
|
deleteVal,
|
|
838
1199
|
extractAllBlocksFromTpl,
|
|
@@ -840,6 +1201,7 @@ export {
|
|
|
840
1201
|
getAIChatModelByTenant,
|
|
841
1202
|
getAIConfigs,
|
|
842
1203
|
getAnnotationsModelByTenant,
|
|
1204
|
+
getChunksModelByTenant,
|
|
843
1205
|
getDbByTenant,
|
|
844
1206
|
getModelByTenant,
|
|
845
1207
|
getPlatformConfigsModelByTenant,
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.3.
|
|
6
|
+
"version": "1.3.9",
|
|
7
7
|
"description": "Utility functions for both browser and Node.js",
|
|
8
8
|
"main": "dist/index.js",
|
|
9
9
|
"module": "dist/index.mjs",
|
|
@@ -74,6 +74,7 @@
|
|
|
74
74
|
"typescript": "^5.8.2"
|
|
75
75
|
},
|
|
76
76
|
"dependencies": {
|
|
77
|
+
"bullmq": "^5.58.2",
|
|
77
78
|
"ioredis": "^5.6.1",
|
|
78
79
|
"mongoose": "^8.15.1"
|
|
79
80
|
}
|