@zintrust/queue-redis 2.4.3 → 2.4.4
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
CHANGED
|
@@ -7,6 +7,7 @@ import { createLockProvider, getLockProvider, registerLockProvider, resolveDedup
|
|
|
7
7
|
import { createRedisConnection, getBullMQSafeQueueName } from '@zintrust/core/redis';
|
|
8
8
|
import { generateUuid, ZintrustLang } from '@zintrust/core/utils';
|
|
9
9
|
import { RedisRpcQueueDriver, shouldUseRedisRpcQueueDriver } from './RedisRpcQueueDriver.js';
|
|
10
|
+
import { resolveRetentionSetting } from './retentionUtils.js';
|
|
10
11
|
// Lazy BullMQ loader keyed on a variable specifier so bundlers (esbuild/wrangler)
|
|
11
12
|
// do not inline bullmq/ioredis into the Workers bundle. Every public method routes
|
|
12
13
|
// through RedisRpcQueueDriver first when shouldUseRedisRpcQueueDriver() is true
|
|
@@ -191,7 +192,7 @@ export const BullMQRedisQueue = (() => {
|
|
|
191
192
|
}
|
|
192
193
|
};
|
|
193
194
|
const getQueue = async (queueName) => {
|
|
194
|
-
const
|
|
195
|
+
const QueueConstructor = await ensureBullmqLoaded();
|
|
195
196
|
// Check if queue exists in cache
|
|
196
197
|
if (queues.has(queueName)) {
|
|
197
198
|
const existingQueue = queues.get(queueName);
|
|
@@ -217,13 +218,13 @@ export const BullMQRedisQueue = (() => {
|
|
|
217
218
|
}
|
|
218
219
|
const connection = getSharedConnection();
|
|
219
220
|
// Customizable BullMQ settings from environment
|
|
220
|
-
const removeOnComplete =
|
|
221
|
-
const removeOnFail =
|
|
221
|
+
const removeOnComplete = resolveRetentionSetting('BULLMQ_REMOVE_ON_COMPLETE', 100);
|
|
222
|
+
const removeOnFail = resolveRetentionSetting('BULLMQ_REMOVE_ON_FAIL', 50);
|
|
222
223
|
const attempts = Env.getInt('BULLMQ_DEFAULT_ATTEMPTS', 3);
|
|
223
224
|
const backoffDelay = Env.getInt('BULLMQ_BACKOFF_DELAY', 2000);
|
|
224
225
|
const backoffType = Env.get('BULLMQ_BACKOFF_TYPE', 'exponential');
|
|
225
226
|
const prefix = getBullMQSafeQueueName();
|
|
226
|
-
const queue = new
|
|
227
|
+
const queue = new QueueConstructor(queueName, {
|
|
227
228
|
connection: connection,
|
|
228
229
|
prefix,
|
|
229
230
|
defaultJobOptions: {
|
|
@@ -267,8 +268,8 @@ export const BullMQRedisQueue = (() => {
|
|
|
267
268
|
// MEDIUM: Job prioritization
|
|
268
269
|
priority: payloadData.priority,
|
|
269
270
|
// CLEANUP: Job retention
|
|
270
|
-
removeOnComplete: payloadData.removeOnComplete
|
|
271
|
-
removeOnFail: payloadData.removeOnFail
|
|
271
|
+
removeOnComplete: payloadData.removeOnComplete ?? resolveRetentionSetting('BULLMQ_REMOVE_ON_COMPLETE', 100),
|
|
272
|
+
removeOnFail: payloadData.removeOnFail ?? resolveRetentionSetting('BULLMQ_REMOVE_ON_FAIL', 50),
|
|
272
273
|
// RETRY: Backoff strategy
|
|
273
274
|
backoff: payloadData.backoff || {
|
|
274
275
|
type: 'exponential',
|
|
@@ -2,6 +2,7 @@ import { Env } from '@zintrust/core/config';
|
|
|
2
2
|
import { ErrorFactory } from '@zintrust/core/errors';
|
|
3
3
|
import { JobStateTracker, TimeoutManager } from '@zintrust/core/queue';
|
|
4
4
|
import { generateUuid } from '@zintrust/core/utils';
|
|
5
|
+
import { resolveRetentionSetting } from './retentionUtils.js';
|
|
5
6
|
export const shouldUseRedisRpcQueueDriver = () => {
|
|
6
7
|
return Env.USE_REDIS_PROXY === true && Env.get('REDIS_RPC_URL', '').trim() !== '';
|
|
7
8
|
};
|
|
@@ -34,13 +35,13 @@ const resolveRequestedJobId = (payloadData) => {
|
|
|
34
35
|
const createJobOptions = (payloadData) => ({
|
|
35
36
|
jobId: resolveRequestedJobId(payloadData),
|
|
36
37
|
delay: payloadData.delay,
|
|
37
|
-
attempts: payloadData.attempts,
|
|
38
|
+
attempts: payloadData.attempts ?? Env.getInt('BULLMQ_DEFAULT_ATTEMPTS', 3),
|
|
38
39
|
priority: payloadData.priority,
|
|
39
|
-
removeOnComplete: payloadData.removeOnComplete
|
|
40
|
-
removeOnFail: payloadData.removeOnFail
|
|
40
|
+
removeOnComplete: payloadData.removeOnComplete ?? resolveRetentionSetting('BULLMQ_REMOVE_ON_COMPLETE', 100),
|
|
41
|
+
removeOnFail: payloadData.removeOnFail ?? resolveRetentionSetting('BULLMQ_REMOVE_ON_FAIL', 50),
|
|
41
42
|
backoff: payloadData.backoff || {
|
|
42
|
-
type: 'exponential',
|
|
43
|
-
delay: 2000,
|
|
43
|
+
type: Env.get('BULLMQ_BACKOFF_TYPE', 'exponential'),
|
|
44
|
+
delay: Env.getInt('BULLMQ_BACKOFF_DELAY', 2000),
|
|
44
45
|
},
|
|
45
46
|
repeat: payloadData.repeat,
|
|
46
47
|
lifo: payloadData.lifo ?? false,
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type RetentionSetting = number | boolean | {
|
|
2
|
+
age: number;
|
|
3
|
+
count?: number;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Resolves a BullMQ retention setting from env.
|
|
7
|
+
*
|
|
8
|
+
* Resolution order:
|
|
9
|
+
* 1. If <key>_AGE_SECONDS is set and <key> is also set → { age, count }
|
|
10
|
+
* 2. If <key>_AGE_SECONDS is set alone → { age }
|
|
11
|
+
* 3. If <key> is set alone → integer count
|
|
12
|
+
* 4. Otherwise → fallbackCount
|
|
13
|
+
*/
|
|
14
|
+
export declare const resolveRetentionSetting: (key: string, fallbackCount: number) => RetentionSetting;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Env } from '@zintrust/core/config';
|
|
2
|
+
/**
|
|
3
|
+
* Resolves a BullMQ retention setting from env.
|
|
4
|
+
*
|
|
5
|
+
* Resolution order:
|
|
6
|
+
* 1. If <key>_AGE_SECONDS is set and <key> is also set → { age, count }
|
|
7
|
+
* 2. If <key>_AGE_SECONDS is set alone → { age }
|
|
8
|
+
* 3. If <key> is set alone → integer count
|
|
9
|
+
* 4. Otherwise → fallbackCount
|
|
10
|
+
*/
|
|
11
|
+
export const resolveRetentionSetting = (key, fallbackCount) => {
|
|
12
|
+
const ageSeconds = Env.getInt(`${key}_AGE_SECONDS`, 0);
|
|
13
|
+
const countRaw = Env.get(key, '').trim();
|
|
14
|
+
if (ageSeconds > 0) {
|
|
15
|
+
if (countRaw.length > 0) {
|
|
16
|
+
return { age: ageSeconds, count: Env.getInt(key, fallbackCount) };
|
|
17
|
+
}
|
|
18
|
+
return { age: ageSeconds };
|
|
19
|
+
}
|
|
20
|
+
return countRaw.length > 0 ? Env.getInt(key, fallbackCount) : fallbackCount;
|
|
21
|
+
};
|