@zintrust/queue-redis 0.4.64 → 0.4.67
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/BullMQRedisQueue.js +8 -2
- package/dist/HttpQueueDriver.js +2 -2
- package/dist/RedisQueue.d.ts +10 -0
- package/dist/RedisQueue.js +92 -0
- package/dist/build-manifest.json +28 -16
- package/dist/register.d.ts +1 -1
- package/dist/register.js +3 -1
- package/package.json +2 -2
package/dist/BullMQRedisQueue.js
CHANGED
|
@@ -228,10 +228,16 @@ export const BullMQRedisQueue = (() => {
|
|
|
228
228
|
const getQueueNames = () => {
|
|
229
229
|
return Array.from(queues.keys());
|
|
230
230
|
};
|
|
231
|
+
const resolveRequestedJobId = (payloadData) => {
|
|
232
|
+
if (typeof payloadData?.jobId === 'string' && payloadData.jobId.trim().length > 0) {
|
|
233
|
+
return payloadData.jobId.trim();
|
|
234
|
+
}
|
|
235
|
+
return generateUuid();
|
|
236
|
+
};
|
|
231
237
|
const createJobOptions = (payloadData) => {
|
|
232
238
|
return {
|
|
233
|
-
//
|
|
234
|
-
jobId: payloadData
|
|
239
|
+
// Prefer the explicit BullMQ jobId and keep uniqueId as a legacy alias.
|
|
240
|
+
jobId: resolveRequestedJobId(payloadData),
|
|
235
241
|
// CRITICAL: Delay scheduling
|
|
236
242
|
delay: payloadData.delay,
|
|
237
243
|
// IMPORTANT: Retry configuration
|
package/dist/HttpQueueDriver.js
CHANGED
|
@@ -154,8 +154,8 @@ const callGateway = async (action, payload) => {
|
|
|
154
154
|
}
|
|
155
155
|
};
|
|
156
156
|
const resolveFallbackJobId = (payload) => {
|
|
157
|
-
if (typeof payload.
|
|
158
|
-
return payload.
|
|
157
|
+
if (typeof payload.jobId === 'string' && payload.jobId.trim().length > 0) {
|
|
158
|
+
return payload.jobId.trim();
|
|
159
159
|
}
|
|
160
160
|
return generateUuid();
|
|
161
161
|
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { QueueMessage } from '@zintrust/core';
|
|
2
|
+
interface IQueueDriver {
|
|
3
|
+
enqueue<T = unknown>(queue: string, payload: T): Promise<string>;
|
|
4
|
+
dequeue<T = unknown>(queue: string): Promise<QueueMessage<T> | undefined>;
|
|
5
|
+
ack(queue: string, id: string): Promise<void>;
|
|
6
|
+
length(queue: string): Promise<number>;
|
|
7
|
+
drain(queue: string): Promise<void>;
|
|
8
|
+
}
|
|
9
|
+
export declare const RedisQueue: IQueueDriver;
|
|
10
|
+
export default RedisQueue;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { ErrorFactory, generateUuid, getRedisUrl, Logger } from '@zintrust/core';
|
|
2
|
+
export const RedisQueue = (() => {
|
|
3
|
+
let client = null;
|
|
4
|
+
let connected = false;
|
|
5
|
+
const ensureClient = async () => {
|
|
6
|
+
if (connected && client !== null)
|
|
7
|
+
return client;
|
|
8
|
+
const url = getRedisUrl();
|
|
9
|
+
if (url === null)
|
|
10
|
+
throw ErrorFactory.createConfigError('Redis queue driver requires REDIS_URL');
|
|
11
|
+
// Import lazily so package is optional for environments that don't use Redis
|
|
12
|
+
try {
|
|
13
|
+
// Prefer the redis package when available
|
|
14
|
+
try {
|
|
15
|
+
const mod = (await import('redis'));
|
|
16
|
+
const createClient = mod.createClient;
|
|
17
|
+
client = createClient({ url });
|
|
18
|
+
if (typeof client.connect === 'function') {
|
|
19
|
+
try {
|
|
20
|
+
await client.connect();
|
|
21
|
+
connected = true;
|
|
22
|
+
}
|
|
23
|
+
catch (connectionError) {
|
|
24
|
+
connected = false;
|
|
25
|
+
Logger.warn('Redis client connect failed:', String(connectionError));
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
connected = true;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
// Fallback to ioredis when available (used by queue-monitor)
|
|
34
|
+
const mod = (await import('ioredis'));
|
|
35
|
+
const redis = mod.default(url);
|
|
36
|
+
client = {
|
|
37
|
+
rPush: (queue, value) => redis.rpush(queue, value),
|
|
38
|
+
lPop: (queue) => redis.lpop(queue),
|
|
39
|
+
lLen: (queue) => redis.llen(queue),
|
|
40
|
+
del: (queue) => redis.del(queue),
|
|
41
|
+
};
|
|
42
|
+
connected = true;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch (error) {
|
|
46
|
+
const globalFake = globalThis
|
|
47
|
+
.__fakeRedisClient;
|
|
48
|
+
if (globalFake === undefined) {
|
|
49
|
+
throw ErrorFactory.createConfigError("Redis queue driver requires the 'redis' or 'ioredis' package (run `zin add queue:redis` / `zin plugin install queue:redis`, or `npm install redis` / `npm install ioredis`) or a test fake client set in globalThis.__fakeRedisClient", error);
|
|
50
|
+
}
|
|
51
|
+
client = globalFake;
|
|
52
|
+
connected = true;
|
|
53
|
+
}
|
|
54
|
+
if (client === null)
|
|
55
|
+
throw ErrorFactory.createConfigError('Redis client could not be initialized');
|
|
56
|
+
return client;
|
|
57
|
+
};
|
|
58
|
+
return {
|
|
59
|
+
async enqueue(queue, payload) {
|
|
60
|
+
const cli = await ensureClient();
|
|
61
|
+
const id = generateUuid();
|
|
62
|
+
const msg = JSON.stringify({ id, payload, attempts: 0 });
|
|
63
|
+
await cli.rPush(queue, msg);
|
|
64
|
+
return id;
|
|
65
|
+
},
|
|
66
|
+
async dequeue(queue) {
|
|
67
|
+
const cli = await ensureClient();
|
|
68
|
+
const raw = await cli.lPop(queue);
|
|
69
|
+
if (raw === null)
|
|
70
|
+
return undefined;
|
|
71
|
+
try {
|
|
72
|
+
const parsed = JSON.parse(raw);
|
|
73
|
+
return parsed;
|
|
74
|
+
}
|
|
75
|
+
catch (err) {
|
|
76
|
+
throw ErrorFactory.createTryCatchError('Failed to parse queue message', err);
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
async ack(_queue, _id) {
|
|
80
|
+
return Promise.resolve(); // NOSONAR
|
|
81
|
+
},
|
|
82
|
+
async length(queue) {
|
|
83
|
+
const cli = await ensureClient();
|
|
84
|
+
return cli.lLen(queue);
|
|
85
|
+
},
|
|
86
|
+
async drain(queue) {
|
|
87
|
+
const cli = await ensureClient();
|
|
88
|
+
await cli.del(queue);
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
})();
|
|
92
|
+
export default RedisQueue;
|
package/dist/build-manifest.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zintrust/queue-redis",
|
|
3
|
-
"version": "0.4.
|
|
4
|
-
"buildDate": "2026-04-
|
|
3
|
+
"version": "0.4.67",
|
|
4
|
+
"buildDate": "2026-04-06T10:10:33.423Z",
|
|
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": "f5a9d786",
|
|
12
|
+
"branch": "release"
|
|
13
13
|
},
|
|
14
14
|
"package": {
|
|
15
15
|
"engines": {
|
|
@@ -29,16 +29,16 @@
|
|
|
29
29
|
"sha256": "52fb0f688cd17cc7d8e8128e60df6f5eea4c803282382ac75550e6aacee7cbb0"
|
|
30
30
|
},
|
|
31
31
|
"BullMQRedisQueue.js": {
|
|
32
|
-
"size":
|
|
33
|
-
"sha256": "
|
|
32
|
+
"size": 21327,
|
|
33
|
+
"sha256": "a35f9d822a3166d57ca48ea1f4894e9fe7996fb842c2f8eeb5cd8be4de866a6a"
|
|
34
34
|
},
|
|
35
35
|
"HttpQueueDriver.d.ts": {
|
|
36
36
|
"size": 835,
|
|
37
37
|
"sha256": "31735e10a83cf905ca48f3bf1c79f40029b9ac7c0ce6c26751ad646fa77bc764"
|
|
38
38
|
},
|
|
39
39
|
"HttpQueueDriver.js": {
|
|
40
|
-
"size":
|
|
41
|
-
"sha256": "
|
|
40
|
+
"size": 8958,
|
|
41
|
+
"sha256": "5e465fe42ff2cc4c5f0366f3a5588ce5870b63e558b09a320da5fa80878eeada"
|
|
42
42
|
},
|
|
43
43
|
"QueueHttpGateway.d.ts": {
|
|
44
44
|
"size": 432,
|
|
@@ -56,21 +56,33 @@
|
|
|
56
56
|
"size": 5464,
|
|
57
57
|
"sha256": "18b785c47b4df689f9969625880d1b559e6cf8c95bb8c3cd3a4112fa75e0d870"
|
|
58
58
|
},
|
|
59
|
+
"RedisQueue.d.ts": {
|
|
60
|
+
"size": 438,
|
|
61
|
+
"sha256": "eefad366ae71d63044b23038265bf3eb60a0277e41ac70f57c5973d79f2af5ce"
|
|
62
|
+
},
|
|
63
|
+
"RedisQueue.js": {
|
|
64
|
+
"size": 3593,
|
|
65
|
+
"sha256": "dc8b2c28b2e288e048423067f90ffbe0389ac813086246a1c8fafeeeab5c142d"
|
|
66
|
+
},
|
|
67
|
+
"build-manifest.json": {
|
|
68
|
+
"size": 2512,
|
|
69
|
+
"sha256": "88571df53755234ef7d08b2da113744ad1d05ca13dd94a6e94318ccc829c0f82"
|
|
70
|
+
},
|
|
59
71
|
"index.d.ts": {
|
|
60
72
|
"size": 565,
|
|
61
73
|
"sha256": "7bc063419989a39530b3a4213627e0aea33fbaacac8c307d9e7e654c99bd5b8d"
|
|
62
74
|
},
|
|
63
75
|
"index.js": {
|
|
64
76
|
"size": 677,
|
|
65
|
-
"sha256": "
|
|
77
|
+
"sha256": "3e9d42c5e835b108067b6c6df606d021ba8a0f7ee8402fe3c3fde6034923b444"
|
|
66
78
|
},
|
|
67
79
|
"register.d.ts": {
|
|
68
|
-
"size":
|
|
69
|
-
"sha256": "
|
|
80
|
+
"size": 170,
|
|
81
|
+
"sha256": "e10ca97976730171bfaaaa25f484a30d06c6dca57c7cd85d700c202e0785a0b7"
|
|
70
82
|
},
|
|
71
83
|
"register.js": {
|
|
72
|
-
"size":
|
|
73
|
-
"sha256": "
|
|
84
|
+
"size": 593,
|
|
85
|
+
"sha256": "9a4ca56fc5d0ae9ca9c5d6c89731b3331749d3e254e583992f311e3ec7add80b"
|
|
74
86
|
}
|
|
75
87
|
}
|
|
76
88
|
}
|
package/dist/register.d.ts
CHANGED
package/dist/register.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export async function registerRedisQueueDriver(queue) {
|
|
2
2
|
const mod = await import('./BullMQRedisQueue.js');
|
|
3
|
+
if (typeof queue.register !== 'function')
|
|
4
|
+
return;
|
|
3
5
|
queue.register('redis', mod.default);
|
|
4
6
|
}
|
|
5
7
|
const importCore = async () => {
|
|
@@ -16,6 +18,6 @@ const importCore = async () => {
|
|
|
16
18
|
}
|
|
17
19
|
};
|
|
18
20
|
const core = (await importCore());
|
|
19
|
-
if (core.Queue
|
|
21
|
+
if (typeof core.Queue?.register === 'function') {
|
|
20
22
|
await registerRedisQueueDriver(core.Queue);
|
|
21
23
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zintrust/queue-redis",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.67",
|
|
4
4
|
"description": "Redis queue driver for ZinTrust.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"node": ">=20.0.0"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
|
-
"@zintrust/core": "^0.4.
|
|
26
|
+
"@zintrust/core": "^0.4.67"
|
|
27
27
|
},
|
|
28
28
|
"publishConfig": {
|
|
29
29
|
"access": "public"
|