@zintrust/queue-redis 0.4.27 → 0.4.36
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 +9 -3
- package/dist/RedisPublishClient.js +11 -105
- package/dist/build-manifest.json +11 -11
- package/package.json +3 -3
package/dist/BullMQRedisQueue.js
CHANGED
|
@@ -60,6 +60,10 @@ export const BullMQRedisQueue = (() => {
|
|
|
60
60
|
if (sharedConnection)
|
|
61
61
|
return sharedConnection;
|
|
62
62
|
const isWorkersRuntime = Cloudflare.getWorkersEnv() !== null;
|
|
63
|
+
const redisProxyEnabled = Env.USE_REDIS_PROXY === true || Env.get('REDIS_PROXY_URL', '').trim() !== '';
|
|
64
|
+
if (redisProxyEnabled && shouldUseHttpProxyDriver() === false) {
|
|
65
|
+
throw ErrorFactory.createConfigError('BullMQ Redis driver does not support REDIS proxy transport directly. Enable QUEUE_HTTP_PROXY_ENABLED=true for queue proxy mode, or disable REDIS proxy mode for direct BullMQ access.');
|
|
66
|
+
}
|
|
63
67
|
if (isWorkersRuntime && Cloudflare.isCloudflareSocketsEnabled() === false) {
|
|
64
68
|
throw ErrorFactory.createConfigError('BullMQ Redis driver requires ENABLE_CLOUDFLARE_SOCKETS=true in Cloudflare Workers. To use HTTP queue proxy mode, set QUEUE_HTTP_PROXY_ENABLED=true and QUEUE_HTTP_PROXY_URL.');
|
|
65
69
|
}
|
|
@@ -92,7 +96,7 @@ export const BullMQRedisQueue = (() => {
|
|
|
92
96
|
port: redisConfig.port,
|
|
93
97
|
password: redisConfig.password,
|
|
94
98
|
db: redisConfig.database,
|
|
95
|
-
});
|
|
99
|
+
}, 3, { subsystem: 'queue-bullmq' });
|
|
96
100
|
return sharedConnection; // sharedConnection is IoRedis (compatible with BullMQ)
|
|
97
101
|
};
|
|
98
102
|
const waitForRedisReady = async (client, timeoutMs) => {
|
|
@@ -308,13 +312,15 @@ export const BullMQRedisQueue = (() => {
|
|
|
308
312
|
? deduplication.ttl
|
|
309
313
|
: undefined;
|
|
310
314
|
const replace = deduplication.replace === true;
|
|
315
|
+
const jobId = jobOptions.jobId ?? generateUuid();
|
|
316
|
+
jobOptions.jobId = jobId;
|
|
311
317
|
// Check existing lock
|
|
312
|
-
const hasExistingLock = await checkExistingLock(deduplicationId, provider, replace, queue,
|
|
318
|
+
const hasExistingLock = await checkExistingLock(deduplicationId, provider, replace, queue, jobId);
|
|
313
319
|
if (hasExistingLock) {
|
|
314
320
|
return { payloadToSend: payloadData, shouldReturn: true, returnValue: deduplicationId };
|
|
315
321
|
}
|
|
316
322
|
// Acquire lock
|
|
317
|
-
const lockAcquired = await acquireDeduplicationLock(deduplicationId, provider, ttl, queue,
|
|
323
|
+
const lockAcquired = await acquireDeduplicationLock(deduplicationId, provider, ttl, queue, jobId);
|
|
318
324
|
if (!lockAcquired) {
|
|
319
325
|
return { payloadToSend: payloadData, shouldReturn: true, returnValue: deduplicationId };
|
|
320
326
|
}
|
|
@@ -1,113 +1,19 @@
|
|
|
1
|
-
import { Env, ErrorFactory,
|
|
2
|
-
const
|
|
3
|
-
try {
|
|
4
|
-
const parsed = new URL(baseUrl);
|
|
5
|
-
const path = parsed.pathname.endsWith('/') ? parsed.pathname.slice(0, -1) : parsed.pathname;
|
|
6
|
-
if (path === '' || path === '/')
|
|
7
|
-
return undefined;
|
|
8
|
-
return path;
|
|
9
|
-
}
|
|
10
|
-
catch {
|
|
11
|
-
return undefined;
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
const buildRequestUrl = (baseUrl, path) => {
|
|
15
|
-
const url = new URL(baseUrl);
|
|
16
|
-
const basePath = url.pathname.endsWith('/') ? url.pathname.slice(0, -1) : url.pathname;
|
|
17
|
-
const requestPath = path.startsWith('/') ? path : `/${path}`;
|
|
18
|
-
url.pathname = `${basePath}${requestPath}`;
|
|
19
|
-
return url;
|
|
20
|
-
};
|
|
21
|
-
const buildSigningUrl = (requestUrl, baseUrl) => {
|
|
22
|
-
const prefix = resolveSigningPrefix(baseUrl);
|
|
23
|
-
if (!prefix)
|
|
24
|
-
return requestUrl;
|
|
25
|
-
if (requestUrl.pathname === prefix || requestUrl.pathname.startsWith(`${prefix}/`)) {
|
|
26
|
-
const signingUrl = new URL(requestUrl.toString());
|
|
27
|
-
const stripped = requestUrl.pathname.slice(prefix.length);
|
|
28
|
-
signingUrl.pathname = stripped.startsWith('/') ? stripped : `/${stripped}`;
|
|
29
|
-
return signingUrl;
|
|
30
|
-
}
|
|
31
|
-
return requestUrl;
|
|
32
|
-
};
|
|
1
|
+
import { Env, ErrorFactory, ZintrustLang, createRedisConnection } from '@zintrust/core';
|
|
2
|
+
const createSharedRedisConnection = createRedisConnection;
|
|
33
3
|
let publishClientInstance = null;
|
|
34
4
|
let publishClientConnected = false;
|
|
35
|
-
const resolveProxyBaseUrl = () => {
|
|
36
|
-
const explicit = Env.REDIS_PROXY_URL.trim();
|
|
37
|
-
if (explicit !== '')
|
|
38
|
-
return explicit;
|
|
39
|
-
if (Env.USE_REDIS_PROXY === false)
|
|
40
|
-
return '';
|
|
41
|
-
const host = Env.REDIS_PROXY_HOST || '127.0.0.1';
|
|
42
|
-
const port = Env.REDIS_PROXY_PORT;
|
|
43
|
-
return `http://${host}:${port}`;
|
|
44
|
-
};
|
|
45
|
-
const buildProxySettings = () => {
|
|
46
|
-
const baseUrl = resolveProxyBaseUrl();
|
|
47
|
-
const keyId = Env.REDIS_PROXY_KEY_ID || undefined;
|
|
48
|
-
const secret = Env.REDIS_PROXY_SECRET || Env.APP_KEY || undefined;
|
|
49
|
-
const timeoutMs = Env.REDIS_PROXY_TIMEOUT_MS;
|
|
50
|
-
return { baseUrl, keyId, secret, timeoutMs };
|
|
51
|
-
};
|
|
52
|
-
const buildHeaders = async (settings, requestUrl, body) => {
|
|
53
|
-
const headers = {
|
|
54
|
-
'Content-Type': 'application/json',
|
|
55
|
-
};
|
|
56
|
-
if (settings.keyId && settings.secret) {
|
|
57
|
-
const signingUrl = buildSigningUrl(requestUrl, settings.baseUrl);
|
|
58
|
-
const signed = await SignedRequest.createHeaders({
|
|
59
|
-
method: 'POST',
|
|
60
|
-
url: signingUrl,
|
|
61
|
-
body,
|
|
62
|
-
keyId: settings.keyId,
|
|
63
|
-
secret: settings.secret,
|
|
64
|
-
});
|
|
65
|
-
Object.assign(headers, signed);
|
|
66
|
-
}
|
|
67
|
-
return headers;
|
|
68
|
-
};
|
|
69
|
-
const requestProxy = async (settings, path, payload) => {
|
|
70
|
-
if (settings.baseUrl.trim() === '') {
|
|
71
|
-
throw ErrorFactory.createConfigError('Redis proxy URL is missing (REDIS_PROXY_URL)');
|
|
72
|
-
}
|
|
73
|
-
const body = JSON.stringify(payload);
|
|
74
|
-
const url = buildRequestUrl(settings.baseUrl, path);
|
|
75
|
-
const headers = await buildHeaders(settings, url, body);
|
|
76
|
-
const timeoutSignal = typeof AbortSignal !== 'undefined' && 'timeout' in AbortSignal;
|
|
77
|
-
const signal = timeoutSignal ? AbortSignal.timeout(settings.timeoutMs) : undefined;
|
|
78
|
-
const response = await fetch(url.toString(), {
|
|
79
|
-
method: 'POST',
|
|
80
|
-
headers,
|
|
81
|
-
body,
|
|
82
|
-
signal,
|
|
83
|
-
});
|
|
84
|
-
if (!response.ok) {
|
|
85
|
-
const text = await response.text();
|
|
86
|
-
throw ErrorFactory.createTryCatchError(`Redis proxy request failed (${response.status})`, text);
|
|
87
|
-
}
|
|
88
|
-
return (await response.json());
|
|
89
|
-
};
|
|
90
|
-
const toNumber = (value) => {
|
|
91
|
-
if (typeof value === 'number')
|
|
92
|
-
return value;
|
|
93
|
-
if (typeof value === 'string') {
|
|
94
|
-
const parsed = Number(value);
|
|
95
|
-
return Number.isFinite(parsed) ? parsed : 0;
|
|
96
|
-
}
|
|
97
|
-
return 0;
|
|
98
|
-
};
|
|
99
5
|
const tryCreateProxyPublishClient = async () => {
|
|
100
|
-
|
|
101
|
-
if (settings.baseUrl.trim() === '')
|
|
6
|
+
if (Env.REDIS_PROXY_URL.trim() === '' && Env.USE_REDIS_PROXY !== true)
|
|
102
7
|
return null;
|
|
8
|
+
const client = createSharedRedisConnection({
|
|
9
|
+
host: Env.get('REDIS_HOST', 'localhost'),
|
|
10
|
+
port: Env.getInt('REDIS_PORT', ZintrustLang.REDIS_DEFAULT_PORT),
|
|
11
|
+
password: Env.get('REDIS_PASSWORD'),
|
|
12
|
+
db: Env.getInt('REDIS_QUEUE_DB', ZintrustLang.REDIS_DEFAULT_DB),
|
|
13
|
+
}, 3, { subsystem: 'broadcast-publish' });
|
|
103
14
|
return {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
command: 'PUBLISH',
|
|
107
|
-
args: [channel, message],
|
|
108
|
-
});
|
|
109
|
-
return toNumber(response.result);
|
|
110
|
-
},
|
|
15
|
+
connect: client.connect,
|
|
16
|
+
publish: (channel, message) => client.publish(channel, message),
|
|
111
17
|
};
|
|
112
18
|
};
|
|
113
19
|
/**
|
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-03-
|
|
3
|
+
"version": "0.4.36",
|
|
4
|
+
"buildDate": "2026-03-30T17:20:00.036Z",
|
|
5
5
|
"buildEnvironment": {
|
|
6
6
|
"node": "v22.22.1",
|
|
7
7
|
"platform": "darwin",
|
|
8
8
|
"arch": "arm64"
|
|
9
9
|
},
|
|
10
10
|
"git": {
|
|
11
|
-
"commit": "
|
|
12
|
-
"branch": "
|
|
11
|
+
"commit": "a45b4628",
|
|
12
|
+
"branch": "release"
|
|
13
13
|
},
|
|
14
14
|
"package": {
|
|
15
15
|
"engines": {
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
"sha256": "52fb0f688cd17cc7d8e8128e60df6f5eea4c803282382ac75550e6aacee7cbb0"
|
|
30
30
|
},
|
|
31
31
|
"BullMQRedisQueue.js": {
|
|
32
|
-
"size":
|
|
33
|
-
"sha256": "
|
|
32
|
+
"size": 20664,
|
|
33
|
+
"sha256": "1ab0050910e2198be2ba1137f0224048d2db5dc49c56afcf6267aeebd4cfbceb"
|
|
34
34
|
},
|
|
35
35
|
"HttpQueueDriver.d.ts": {
|
|
36
36
|
"size": 835,
|
|
@@ -53,8 +53,8 @@
|
|
|
53
53
|
"sha256": "341a68a3b8603b453146dc721f9d2eaf0d65bb6a1acb67908a9c6f9542b9fd2d"
|
|
54
54
|
},
|
|
55
55
|
"RedisPublishClient.js": {
|
|
56
|
-
"size":
|
|
57
|
-
"sha256": "
|
|
56
|
+
"size": 5464,
|
|
57
|
+
"sha256": "18b785c47b4df689f9969625880d1b559e6cf8c95bb8c3cd3a4112fa75e0d870"
|
|
58
58
|
},
|
|
59
59
|
"RedisQueue.d.ts": {
|
|
60
60
|
"size": 438,
|
|
@@ -65,8 +65,8 @@
|
|
|
65
65
|
"sha256": "dc8b2c28b2e288e048423067f90ffbe0389ac813086246a1c8fafeeeab5c142d"
|
|
66
66
|
},
|
|
67
67
|
"build-manifest.json": {
|
|
68
|
-
"size":
|
|
69
|
-
"sha256": "
|
|
68
|
+
"size": 2508,
|
|
69
|
+
"sha256": "43b33ece1a7563efa31418c9d1c86e3063db29f228c85e1fa6dfb68d549da3f3"
|
|
70
70
|
},
|
|
71
71
|
"index.d.ts": {
|
|
72
72
|
"size": 565,
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
},
|
|
75
75
|
"index.js": {
|
|
76
76
|
"size": 677,
|
|
77
|
-
"sha256": "
|
|
77
|
+
"sha256": "323f917f0f5e249243c6156559895fd2f3a0a26c376691cb09e18ba1cd3e0ac9"
|
|
78
78
|
},
|
|
79
79
|
"register.d.ts": {
|
|
80
80
|
"size": 169,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zintrust/queue-redis",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.36",
|
|
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.36"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@zintrust/core": "file:../../dist"
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"prepublishOnly": "npm run build"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"ioredis": "^5.10.
|
|
46
|
+
"ioredis": "^5.10.1",
|
|
47
47
|
"redis": "^5.11.0"
|
|
48
48
|
}
|
|
49
49
|
}
|