@zintrust/workers 2.8.1 → 3.0.1
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/build-manifest.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zintrust/workers",
|
|
3
3
|
"version": "2.8.1",
|
|
4
|
-
"buildDate": "2026-06-
|
|
4
|
+
"buildDate": "2026-06-27T08:39:32.101Z",
|
|
5
5
|
"buildEnvironment": {
|
|
6
|
-
"node": "
|
|
7
|
-
"platform": "
|
|
8
|
-
"arch": "
|
|
6
|
+
"node": "v22.22.1",
|
|
7
|
+
"platform": "darwin",
|
|
8
|
+
"arch": "arm64"
|
|
9
9
|
},
|
|
10
10
|
"git": {
|
|
11
|
-
"commit": "
|
|
12
|
-
"branch": "
|
|
11
|
+
"commit": "731f5512",
|
|
12
|
+
"branch": "release"
|
|
13
13
|
},
|
|
14
14
|
"package": {
|
|
15
15
|
"engines": {
|
|
@@ -222,6 +222,10 @@
|
|
|
222
222
|
"size": 11000,
|
|
223
223
|
"sha256": "9aedd369e9a3e409845929da17e14975bbc53a3ed1f6eebf62b464dda170a5bb"
|
|
224
224
|
},
|
|
225
|
+
"build-manifest.json": {
|
|
226
|
+
"size": 19617,
|
|
227
|
+
"sha256": "6821a78856f304d56a6291e04ec500936a9a823b1a32bad48810e8d6ce0e1801"
|
|
228
|
+
},
|
|
225
229
|
"config/workerConfig.d.ts": {
|
|
226
230
|
"size": 282,
|
|
227
231
|
"sha256": "4671566a0cba372852c049ba66f7671ec19f5db38b0eaed1815eb532e7d58109"
|
|
@@ -412,7 +416,7 @@
|
|
|
412
416
|
},
|
|
413
417
|
"index.js": {
|
|
414
418
|
"size": 2428,
|
|
415
|
-
"sha256": "
|
|
419
|
+
"sha256": "11666375858d8052eb83fc7dd0604519a5ef50f13a9a7fd4410254e1176f8646"
|
|
416
420
|
},
|
|
417
421
|
"queueMonitorHistory.d.ts": {
|
|
418
422
|
"size": 433,
|
|
@@ -4,6 +4,7 @@ export interface WorkerConfiguration {
|
|
|
4
4
|
[key: string]: string | number | boolean | null | undefined | object;
|
|
5
5
|
}
|
|
6
6
|
export type WorkerDriver = 'database' | 'redis' | 'memory';
|
|
7
|
+
export type QueueDataDriver = WorkerDriver | 'zedgi';
|
|
7
8
|
export type WorkerStatus = 'running' | 'stopped' | 'error' | 'paused';
|
|
8
9
|
export type WorkerSortBy = 'name' | 'status' | 'driver' | 'health' | 'version' | 'processed';
|
|
9
10
|
export type WorkerSortOrder = 'asc' | 'desc';
|
|
@@ -71,7 +72,7 @@ export interface WorkersListResponse {
|
|
|
71
72
|
};
|
|
72
73
|
}
|
|
73
74
|
export interface QueueData {
|
|
74
|
-
driver:
|
|
75
|
+
driver: QueueDataDriver;
|
|
75
76
|
totalQueues: number;
|
|
76
77
|
totalJobs: number;
|
|
77
78
|
processingJobs: number;
|
|
@@ -396,10 +396,18 @@ const normalizeDriver = (driver) => {
|
|
|
396
396
|
return 'memory';
|
|
397
397
|
};
|
|
398
398
|
const normalizeQueueDriver = (driver) => {
|
|
399
|
+
if (driver === 'queue-zedgi' || driver === 'zedgi')
|
|
400
|
+
return 'zedgi';
|
|
399
401
|
return normalizeDriver(driver);
|
|
400
402
|
};
|
|
403
|
+
const resolveActiveQueueConnection = () => {
|
|
404
|
+
const connection = Env.get('QUEUE_CONNECTION', '').trim();
|
|
405
|
+
if (connection !== '')
|
|
406
|
+
return connection;
|
|
407
|
+
return Env.get('QUEUE_DRIVER', 'redis');
|
|
408
|
+
};
|
|
401
409
|
const resolveConfiguredQueueDriver = () => {
|
|
402
|
-
return normalizeQueueDriver(
|
|
410
|
+
return normalizeQueueDriver(resolveActiveQueueConnection());
|
|
403
411
|
};
|
|
404
412
|
const buildEmptyQueueData = (driver) => {
|
|
405
413
|
return {
|
|
@@ -587,10 +595,12 @@ function applySorting(workers, sortBy, sortOrder = 'asc') {
|
|
|
587
595
|
async function getQueueData() {
|
|
588
596
|
const queueDriver = resolveConfiguredQueueDriver();
|
|
589
597
|
try {
|
|
590
|
-
// Get queue statistics based on
|
|
598
|
+
// Get queue statistics based on the active queue connection.
|
|
591
599
|
switch (queueDriver) {
|
|
592
600
|
case 'redis':
|
|
593
601
|
return await getRedisQueueData();
|
|
602
|
+
case 'zedgi':
|
|
603
|
+
return await getZedgiQueueData();
|
|
594
604
|
case 'database':
|
|
595
605
|
return await getDatabaseQueueData();
|
|
596
606
|
default:
|
|
@@ -602,54 +612,56 @@ async function getQueueData() {
|
|
|
602
612
|
return buildEmptyQueueData(queueDriver);
|
|
603
613
|
}
|
|
604
614
|
}
|
|
615
|
+
const getKnownWorkerQueues = async () => {
|
|
616
|
+
const manifestQueues = getWorkerManifestQueueNames();
|
|
617
|
+
if (shouldUseRedisRpcWorkerApi() && manifestQueues.length > 0) {
|
|
618
|
+
return manifestQueues;
|
|
619
|
+
}
|
|
620
|
+
const records = await WorkerFactory.listPersistedRecords();
|
|
621
|
+
return Array.from(new Set(records
|
|
622
|
+
.map((record) => record.queueName)
|
|
623
|
+
.filter((queueName) => typeof queueName === 'string'))).sort((left, right) => left.localeCompare(right));
|
|
624
|
+
};
|
|
625
|
+
const summarizeQueueMonitor = async (driver, redis) => {
|
|
626
|
+
const { QueueMonitor } = await import('@zintrust/queue-monitor');
|
|
627
|
+
const monitor = QueueMonitor.create({
|
|
628
|
+
knownQueues: getKnownWorkerQueues,
|
|
629
|
+
redis,
|
|
630
|
+
});
|
|
631
|
+
const snapshot = await monitor.getSnapshot();
|
|
632
|
+
let totalJobs = 0;
|
|
633
|
+
let processingJobs = 0;
|
|
634
|
+
let failedJobs = 0;
|
|
635
|
+
for (const queue of snapshot.queues) {
|
|
636
|
+
totalJobs +=
|
|
637
|
+
(queue.counts.waiting || 0) +
|
|
638
|
+
(queue.counts.active || 0) +
|
|
639
|
+
(queue.counts.completed || 0) +
|
|
640
|
+
(queue.counts.failed || 0);
|
|
641
|
+
processingJobs += queue.counts.active || 0;
|
|
642
|
+
failedJobs += queue.counts.failed || 0;
|
|
643
|
+
}
|
|
644
|
+
return {
|
|
645
|
+
driver,
|
|
646
|
+
totalQueues: snapshot.queues.length,
|
|
647
|
+
totalJobs,
|
|
648
|
+
processingJobs,
|
|
649
|
+
failedJobs,
|
|
650
|
+
};
|
|
651
|
+
};
|
|
605
652
|
async function getRedisQueueData() {
|
|
606
653
|
try {
|
|
607
|
-
// Use existing queue monitor infrastructure
|
|
608
|
-
const { QueueMonitor } = await import('@zintrust/queue-monitor');
|
|
609
654
|
const { queueConfig: FreshQeueConfig } = await import('@zintrust/core/config');
|
|
610
655
|
const redisConfig = FreshQeueConfig.drivers.redis;
|
|
611
656
|
if (redisConfig?.driver !== 'redis') {
|
|
612
657
|
throw ErrorFactory.createConfigError('Redis driver not configured');
|
|
613
658
|
}
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
}
|
|
620
|
-
const records = await WorkerFactory.listPersistedRecords();
|
|
621
|
-
return Array.from(new Set(records
|
|
622
|
-
.map((record) => record.queueName)
|
|
623
|
-
.filter((queueName) => typeof queueName === 'string'))).sort((left, right) => left.localeCompare(right));
|
|
624
|
-
},
|
|
625
|
-
redis: {
|
|
626
|
-
host: redisConfig.host || 'localhost',
|
|
627
|
-
port: redisConfig.port || 6379,
|
|
628
|
-
db: redisConfig.database || 1,
|
|
629
|
-
password: redisConfig.password,
|
|
630
|
-
},
|
|
659
|
+
return await summarizeQueueMonitor('redis', {
|
|
660
|
+
host: redisConfig.host || 'localhost',
|
|
661
|
+
port: redisConfig.port || 6379,
|
|
662
|
+
db: redisConfig.database || 1,
|
|
663
|
+
password: redisConfig.password,
|
|
631
664
|
});
|
|
632
|
-
const snapshot = await monitor.getSnapshot();
|
|
633
|
-
let totalJobs = 0;
|
|
634
|
-
let processingJobs = 0;
|
|
635
|
-
let failedJobs = 0;
|
|
636
|
-
// Aggregate stats from all queues
|
|
637
|
-
for (const queue of snapshot.queues) {
|
|
638
|
-
totalJobs +=
|
|
639
|
-
(queue.counts.waiting || 0) +
|
|
640
|
-
(queue.counts.active || 0) +
|
|
641
|
-
(queue.counts.completed || 0) +
|
|
642
|
-
(queue.counts.failed || 0);
|
|
643
|
-
processingJobs += queue.counts.active || 0;
|
|
644
|
-
failedJobs += queue.counts.failed || 0;
|
|
645
|
-
}
|
|
646
|
-
return {
|
|
647
|
-
driver: 'redis',
|
|
648
|
-
totalQueues: snapshot.queues.length,
|
|
649
|
-
totalJobs,
|
|
650
|
-
processingJobs,
|
|
651
|
-
failedJobs,
|
|
652
|
-
};
|
|
653
665
|
}
|
|
654
666
|
catch (error) {
|
|
655
667
|
if (shouldUseRedisRpcWorkerApi()) {
|
|
@@ -667,6 +679,25 @@ async function getRedisQueueData() {
|
|
|
667
679
|
};
|
|
668
680
|
}
|
|
669
681
|
}
|
|
682
|
+
async function getZedgiQueueData() {
|
|
683
|
+
try {
|
|
684
|
+
const { queueConfig: FreshQeueConfig } = await import('@zintrust/core/config');
|
|
685
|
+
const zedgiConfig = FreshQeueConfig.drivers['queue-zedgi'];
|
|
686
|
+
if (zedgiConfig?.driver !== 'queue-zedgi') {
|
|
687
|
+
throw ErrorFactory.createConfigError('Zedgi queue driver not configured');
|
|
688
|
+
}
|
|
689
|
+
return await summarizeQueueMonitor('zedgi', {
|
|
690
|
+
db: zedgiConfig.database,
|
|
691
|
+
password: zedgiConfig.password,
|
|
692
|
+
header: zedgiConfig.header,
|
|
693
|
+
profile: zedgiConfig.profile,
|
|
694
|
+
});
|
|
695
|
+
}
|
|
696
|
+
catch (error) {
|
|
697
|
+
Logger.debug('Error fetching Zedgi queue data:', error);
|
|
698
|
+
return buildEmptyQueueData('zedgi');
|
|
699
|
+
}
|
|
700
|
+
}
|
|
670
701
|
async function getDatabaseQueueData() {
|
|
671
702
|
try {
|
|
672
703
|
// For database queues, use the existing database connection
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zintrust/workers",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"description": "Worker orchestration and background job management for ZinTrust.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -81,4 +81,4 @@
|
|
|
81
81
|
"prom-client": "^15.1.3",
|
|
82
82
|
"simple-statistics": "^7.8.9"
|
|
83
83
|
}
|
|
84
|
-
}
|
|
84
|
+
}
|
package/src/dashboard/types.ts
CHANGED
|
@@ -6,6 +6,7 @@ export interface WorkerConfiguration {
|
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
export type WorkerDriver = 'database' | 'redis' | 'memory';
|
|
9
|
+
export type QueueDataDriver = WorkerDriver | 'zedgi';
|
|
9
10
|
|
|
10
11
|
export type WorkerStatus = 'running' | 'stopped' | 'error' | 'paused';
|
|
11
12
|
|
|
@@ -88,7 +89,7 @@ export interface WorkersListResponse {
|
|
|
88
89
|
|
|
89
90
|
// Queue Data Types
|
|
90
91
|
export interface QueueData {
|
|
91
|
-
driver:
|
|
92
|
+
driver: QueueDataDriver;
|
|
92
93
|
totalQueues: number;
|
|
93
94
|
totalJobs: number;
|
|
94
95
|
processingJobs: number;
|
|
@@ -12,6 +12,7 @@ import type {
|
|
|
12
12
|
QueueData,
|
|
13
13
|
RawWorkerData,
|
|
14
14
|
WorkerConfiguration,
|
|
15
|
+
QueueDataDriver,
|
|
15
16
|
WorkerData,
|
|
16
17
|
WorkerDriver,
|
|
17
18
|
WorkerHealth,
|
|
@@ -552,15 +553,22 @@ const normalizeDriver = (driver: string): WorkerDriver => {
|
|
|
552
553
|
return 'memory';
|
|
553
554
|
};
|
|
554
555
|
|
|
555
|
-
const normalizeQueueDriver = (driver: string):
|
|
556
|
+
const normalizeQueueDriver = (driver: string): QueueDataDriver => {
|
|
557
|
+
if (driver === 'queue-zedgi' || driver === 'zedgi') return 'zedgi';
|
|
556
558
|
return normalizeDriver(driver);
|
|
557
559
|
};
|
|
558
560
|
|
|
559
|
-
const
|
|
560
|
-
|
|
561
|
+
const resolveActiveQueueConnection = (): string => {
|
|
562
|
+
const connection = Env.get('QUEUE_CONNECTION', '').trim();
|
|
563
|
+
if (connection !== '') return connection;
|
|
564
|
+
return Env.get('QUEUE_DRIVER', 'redis');
|
|
561
565
|
};
|
|
562
566
|
|
|
563
|
-
const
|
|
567
|
+
const resolveConfiguredQueueDriver = (): QueueDataDriver => {
|
|
568
|
+
return normalizeQueueDriver(resolveActiveQueueConnection());
|
|
569
|
+
};
|
|
570
|
+
|
|
571
|
+
const buildEmptyQueueData = (driver: QueueDataDriver): QueueData => {
|
|
564
572
|
return {
|
|
565
573
|
driver,
|
|
566
574
|
totalQueues: 0,
|
|
@@ -780,10 +788,12 @@ async function getQueueData(): Promise<QueueData> {
|
|
|
780
788
|
const queueDriver = resolveConfiguredQueueDriver();
|
|
781
789
|
|
|
782
790
|
try {
|
|
783
|
-
// Get queue statistics based on
|
|
791
|
+
// Get queue statistics based on the active queue connection.
|
|
784
792
|
switch (queueDriver) {
|
|
785
793
|
case 'redis':
|
|
786
794
|
return await getRedisQueueData();
|
|
795
|
+
case 'zedgi':
|
|
796
|
+
return await getZedgiQueueData();
|
|
787
797
|
case 'database':
|
|
788
798
|
return await getDatabaseQueueData();
|
|
789
799
|
default:
|
|
@@ -795,10 +805,67 @@ async function getQueueData(): Promise<QueueData> {
|
|
|
795
805
|
}
|
|
796
806
|
}
|
|
797
807
|
|
|
808
|
+
type QueueMonitorRedisConfig = {
|
|
809
|
+
host?: string;
|
|
810
|
+
port?: number;
|
|
811
|
+
db?: number;
|
|
812
|
+
password?: string;
|
|
813
|
+
header?: Record<string, unknown>;
|
|
814
|
+
profile?: string;
|
|
815
|
+
};
|
|
816
|
+
|
|
817
|
+
const getKnownWorkerQueues = async (): Promise<string[]> => {
|
|
818
|
+
const manifestQueues = getWorkerManifestQueueNames();
|
|
819
|
+
if (shouldUseRedisRpcWorkerApi() && manifestQueues.length > 0) {
|
|
820
|
+
return manifestQueues;
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
const records = await WorkerFactory.listPersistedRecords();
|
|
824
|
+
return Array.from(
|
|
825
|
+
new Set(
|
|
826
|
+
records
|
|
827
|
+
.map((record) => record.queueName)
|
|
828
|
+
.filter((queueName): queueName is string => typeof queueName === 'string')
|
|
829
|
+
)
|
|
830
|
+
).sort((left, right) => left.localeCompare(right));
|
|
831
|
+
};
|
|
832
|
+
|
|
833
|
+
const summarizeQueueMonitor = async (
|
|
834
|
+
driver: QueueDataDriver,
|
|
835
|
+
redis: QueueMonitorRedisConfig
|
|
836
|
+
): Promise<QueueData> => {
|
|
837
|
+
const { QueueMonitor } = await import('@zintrust/queue-monitor');
|
|
838
|
+
const monitor = QueueMonitor.create({
|
|
839
|
+
knownQueues: getKnownWorkerQueues,
|
|
840
|
+
redis,
|
|
841
|
+
});
|
|
842
|
+
const snapshot = await monitor.getSnapshot();
|
|
843
|
+
|
|
844
|
+
let totalJobs = 0;
|
|
845
|
+
let processingJobs = 0;
|
|
846
|
+
let failedJobs = 0;
|
|
847
|
+
|
|
848
|
+
for (const queue of snapshot.queues) {
|
|
849
|
+
totalJobs +=
|
|
850
|
+
(queue.counts.waiting || 0) +
|
|
851
|
+
(queue.counts.active || 0) +
|
|
852
|
+
(queue.counts.completed || 0) +
|
|
853
|
+
(queue.counts.failed || 0);
|
|
854
|
+
processingJobs += queue.counts.active || 0;
|
|
855
|
+
failedJobs += queue.counts.failed || 0;
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
return {
|
|
859
|
+
driver,
|
|
860
|
+
totalQueues: snapshot.queues.length,
|
|
861
|
+
totalJobs,
|
|
862
|
+
processingJobs,
|
|
863
|
+
failedJobs,
|
|
864
|
+
};
|
|
865
|
+
};
|
|
866
|
+
|
|
798
867
|
async function getRedisQueueData(): Promise<QueueData> {
|
|
799
868
|
try {
|
|
800
|
-
// Use existing queue monitor infrastructure
|
|
801
|
-
const { QueueMonitor } = await import('@zintrust/queue-monitor');
|
|
802
869
|
const { queueConfig: FreshQeueConfig } = await import('@zintrust/core/config');
|
|
803
870
|
|
|
804
871
|
const redisConfig = FreshQeueConfig.drivers.redis;
|
|
@@ -806,53 +873,12 @@ async function getRedisQueueData(): Promise<QueueData> {
|
|
|
806
873
|
throw ErrorFactory.createConfigError('Redis driver not configured');
|
|
807
874
|
}
|
|
808
875
|
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
}
|
|
815
|
-
|
|
816
|
-
const records = await WorkerFactory.listPersistedRecords();
|
|
817
|
-
return Array.from(
|
|
818
|
-
new Set(
|
|
819
|
-
records
|
|
820
|
-
.map((record) => record.queueName)
|
|
821
|
-
.filter((queueName) => typeof queueName === 'string')
|
|
822
|
-
)
|
|
823
|
-
).sort((left, right) => left.localeCompare(right));
|
|
824
|
-
},
|
|
825
|
-
redis: {
|
|
826
|
-
host: redisConfig.host || 'localhost',
|
|
827
|
-
port: redisConfig.port || 6379,
|
|
828
|
-
db: redisConfig.database || 1,
|
|
829
|
-
password: redisConfig.password,
|
|
830
|
-
},
|
|
876
|
+
return await summarizeQueueMonitor('redis', {
|
|
877
|
+
host: redisConfig.host || 'localhost',
|
|
878
|
+
port: redisConfig.port || 6379,
|
|
879
|
+
db: redisConfig.database || 1,
|
|
880
|
+
password: redisConfig.password,
|
|
831
881
|
});
|
|
832
|
-
const snapshot = await monitor.getSnapshot();
|
|
833
|
-
|
|
834
|
-
let totalJobs = 0;
|
|
835
|
-
let processingJobs = 0;
|
|
836
|
-
let failedJobs = 0;
|
|
837
|
-
|
|
838
|
-
// Aggregate stats from all queues
|
|
839
|
-
for (const queue of snapshot.queues) {
|
|
840
|
-
totalJobs +=
|
|
841
|
-
(queue.counts.waiting || 0) +
|
|
842
|
-
(queue.counts.active || 0) +
|
|
843
|
-
(queue.counts.completed || 0) +
|
|
844
|
-
(queue.counts.failed || 0);
|
|
845
|
-
processingJobs += queue.counts.active || 0;
|
|
846
|
-
failedJobs += queue.counts.failed || 0;
|
|
847
|
-
}
|
|
848
|
-
|
|
849
|
-
return {
|
|
850
|
-
driver: 'redis',
|
|
851
|
-
totalQueues: snapshot.queues.length,
|
|
852
|
-
totalJobs,
|
|
853
|
-
processingJobs,
|
|
854
|
-
failedJobs,
|
|
855
|
-
};
|
|
856
882
|
} catch (error) {
|
|
857
883
|
if (shouldUseRedisRpcWorkerApi()) {
|
|
858
884
|
Logger.debug('Error fetching Redis queue data:', error);
|
|
@@ -869,6 +895,26 @@ async function getRedisQueueData(): Promise<QueueData> {
|
|
|
869
895
|
}
|
|
870
896
|
}
|
|
871
897
|
|
|
898
|
+
async function getZedgiQueueData(): Promise<QueueData> {
|
|
899
|
+
try {
|
|
900
|
+
const { queueConfig: FreshQeueConfig } = await import('@zintrust/core/config');
|
|
901
|
+
const zedgiConfig = FreshQeueConfig.drivers['queue-zedgi'];
|
|
902
|
+
if (zedgiConfig?.driver !== 'queue-zedgi') {
|
|
903
|
+
throw ErrorFactory.createConfigError('Zedgi queue driver not configured');
|
|
904
|
+
}
|
|
905
|
+
|
|
906
|
+
return await summarizeQueueMonitor('zedgi', {
|
|
907
|
+
db: zedgiConfig.database,
|
|
908
|
+
password: zedgiConfig.password,
|
|
909
|
+
header: zedgiConfig.header,
|
|
910
|
+
profile: (zedgiConfig as { profile?: string }).profile,
|
|
911
|
+
});
|
|
912
|
+
} catch (error) {
|
|
913
|
+
Logger.debug('Error fetching Zedgi queue data:', error);
|
|
914
|
+
return buildEmptyQueueData('zedgi');
|
|
915
|
+
}
|
|
916
|
+
}
|
|
917
|
+
|
|
872
918
|
async function getDatabaseQueueData(): Promise<QueueData> {
|
|
873
919
|
try {
|
|
874
920
|
// For database queues, use the existing database connection
|