@zintrust/queue-redis 2.4.2 → 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.
@@ -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 QueueCtor = await ensureBullmqLoaded();
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 = Env.getInt('BULLMQ_REMOVE_ON_COMPLETE', 100);
221
- const removeOnFail = Env.getInt('BULLMQ_REMOVE_ON_FAIL', 50);
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 QueueCtor(queueName, {
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 || 100,
271
- removeOnFail: payloadData.removeOnFail || 50,
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,7 +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
- const REDIS_RPC_PACKAGE = '@zintrust/redis-rpc';
5
+ import { resolveRetentionSetting } from './retentionUtils.js';
6
6
  export const shouldUseRedisRpcQueueDriver = () => {
7
7
  return Env.USE_REDIS_PROXY === true && Env.get('REDIS_RPC_URL', '').trim() !== '';
8
8
  };
@@ -16,8 +16,8 @@ const resolveRpcBaseUrl = () => {
16
16
  };
17
17
  const createRpcClient = async () => {
18
18
  try {
19
- const mod = (await import(REDIS_RPC_PACKAGE));
20
- return mod.createRedisRpcClient({
19
+ const { createRedisRpcClient } = await import('@zintrust/redis-rpc/client');
20
+ return createRedisRpcClient({
21
21
  baseUrl: resolveRpcBaseUrl(),
22
22
  secret: Env.get('REDIS_RPC_SECRET', Env.get('REDIS_PROXY_SECRET', Env.APP_KEY)),
23
23
  });
@@ -35,13 +35,13 @@ const resolveRequestedJobId = (payloadData) => {
35
35
  const createJobOptions = (payloadData) => ({
36
36
  jobId: resolveRequestedJobId(payloadData),
37
37
  delay: payloadData.delay,
38
- attempts: payloadData.attempts,
38
+ attempts: payloadData.attempts ?? Env.getInt('BULLMQ_DEFAULT_ATTEMPTS', 3),
39
39
  priority: payloadData.priority,
40
- removeOnComplete: payloadData.removeOnComplete || 100,
41
- removeOnFail: payloadData.removeOnFail || 50,
40
+ removeOnComplete: payloadData.removeOnComplete ?? resolveRetentionSetting('BULLMQ_REMOVE_ON_COMPLETE', 100),
41
+ removeOnFail: payloadData.removeOnFail ?? resolveRetentionSetting('BULLMQ_REMOVE_ON_FAIL', 50),
42
42
  backoff: payloadData.backoff || {
43
- type: 'exponential',
44
- delay: 2000,
43
+ type: Env.get('BULLMQ_BACKOFF_TYPE', 'exponential'),
44
+ delay: Env.getInt('BULLMQ_BACKOFF_DELAY', 2000),
45
45
  },
46
46
  repeat: payloadData.repeat,
47
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
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zintrust/queue-redis",
3
- "version": "2.4.2",
3
+ "version": "2.4.4",
4
4
  "description": "Redis queue driver for ZinTrust.",
5
5
  "private": false,
6
6
  "type": "module",