power-queues 2.1.3 → 2.1.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/index.cjs CHANGED
@@ -275,7 +275,7 @@ var PowerQueues = class extends import_power_redis.PowerRedis {
275
275
  this.selectStuckTimeout = 6e4;
276
276
  this.selectStuckMaxTimeout = 80;
277
277
  this.selectCount = 200;
278
- this.selectTimeout = 5e3;
278
+ this.selectTimeout = 3e3;
279
279
  this.buildBatchCount = 800;
280
280
  this.buildBatchMaxCount = 1e4;
281
281
  this.retryCount = 1;
@@ -283,7 +283,7 @@ var PowerQueues = class extends import_power_redis.PowerRedis {
283
283
  this.idemLockTimeout = 18e4;
284
284
  this.idemDoneTimeout = 6e4;
285
285
  this.logStatus = false;
286
- this.logStatusTimeout = 6e5;
286
+ this.logStatusTimeout = 18e5;
287
287
  this.approveCount = 2e3;
288
288
  this.removeOnExecuted = true;
289
289
  }
@@ -339,17 +339,26 @@ var PowerQueues = class extends import_power_redis.PowerRedis {
339
339
  if (!filtered[key]) {
340
340
  filtered[key] = [];
341
341
  }
342
- filtered[key].push(tasks[index]);
342
+ filtered[key].push(tasks[index][1]);
343
343
  });
344
344
  for (let key in filtered) {
345
345
  const filteredTasks = filtered[key];
346
346
  const keySplit = key.split(":");
347
347
  const attempt = Number(keySplit[0]);
348
- await this.addTasks(queueName + (attempt >= this.retryCount - 1 ? ":dlq" : ""), filteredTasks.map((task) => ({ ...task[1] })), {
349
- createdAt: Number(keySplit[1]),
350
- job: keySplit[2],
351
- attempt: attempt + 1
352
- });
348
+ const job = String(keySplit[2]);
349
+ if (!(attempt >= this.retryCount - 1)) {
350
+ await this.addTasks(queueName, filteredTasks, {
351
+ job,
352
+ attempt: attempt + 1
353
+ });
354
+ } else if (this.logStatus) {
355
+ const statusKey = `${queueName}:${job}:`;
356
+ await this.setOne(statusKey + "err", Number(await this.getOne(statusKey + "err") || 0) + filteredTasks.length, this.logStatusTimeout);
357
+ await this.setOne(statusKey + "ready", Number(await this.getOne(statusKey + "ready") || 0) + filteredTasks.length, this.logStatusTimeout);
358
+ await this.addTasks(queueName + ":dlq", filteredTasks, {
359
+ job
360
+ });
361
+ }
353
362
  }
354
363
  } catch (err2) {
355
364
  throw new Error(`Batch error. ${err2.message}`);
@@ -469,8 +478,9 @@ var PowerQueues = class extends import_power_redis.PowerRedis {
469
478
  }
470
479
  }
471
480
  }
481
+ let start = Date.now();
472
482
  if (!this.executeSync && promises.length > 0) {
473
- await Promise.all(promises.map((item) => item));
483
+ await Promise.all(promises.map((item) => item()));
474
484
  }
475
485
  await this.onBatchReady(queueName, result);
476
486
  if (!(0, import_full_utils.isArrFilled)(result) && contended > tasks.length >> 1) {
@@ -549,26 +559,24 @@ var PowerQueues = class extends import_power_redis.PowerRedis {
549
559
  return await this.onSuccess(queueName, task);
550
560
  }
551
561
  async error(err, queueName, task) {
552
- const dlqKey = queueName + ":dlq";
553
562
  const taskP = { ...task };
554
- if (taskP.attempt >= this.retryCount - 1) {
555
- const statusKey = `${queueName}:${taskP.job}:`;
556
- if (this.logStatus) {
557
- await this.incr(statusKey + "err", this.logStatusTimeout);
558
- await this.incr(statusKey + "ready", this.logStatusTimeout);
559
- }
560
- await this.addTasks(dlqKey, [{ ...taskP.payload }], {
561
- createdAt: taskP.createdAt,
562
- job: taskP.job,
563
- attempt: taskP.attempt
564
- });
565
- } else {
563
+ if (!(taskP.attempt >= this.retryCount - 1)) {
566
564
  await this.onRetry(err, queueName, taskP);
567
565
  await this.addTasks(queueName, [{ ...taskP.payload }], {
568
566
  createdAt: taskP.createdAt,
569
567
  job: taskP.job,
570
568
  attempt: (taskP.attempt || 0) + 1
571
569
  });
570
+ } else if (this.logStatus) {
571
+ const dlqKey = queueName + ":dlq";
572
+ const statusKey = `${queueName}:${taskP.job}:`;
573
+ await this.incr(statusKey + "err", this.logStatusTimeout);
574
+ await this.incr(statusKey + "ready", this.logStatusTimeout);
575
+ await this.addTasks(dlqKey, [{ ...taskP.payload }], {
576
+ createdAt: taskP.createdAt,
577
+ job: taskP.job,
578
+ attempt: taskP.attempt
579
+ });
572
580
  }
573
581
  return await this.onError(err, queueName, { ...taskP, attempt: (taskP.attempt || 0) + 1 });
574
582
  }
package/dist/index.d.cts CHANGED
@@ -83,7 +83,7 @@ declare class PowerQueues extends PowerRedis {
83
83
  private payloadBatch;
84
84
  beforeExecute(queueName: string, tasks: Array<[string, any, number, string, string, number]>): Promise<[string, any, number, string, string, number][]>;
85
85
  onExecute(queueName: string, task: Task): Promise<Task>;
86
- onBatchReady(queueName: string, tasks: Array<Task>): Promise<void>;
86
+ onBatchReady(queueName: string, tasks: Task[]): Promise<void>;
87
87
  onSuccess(queueName: string, task: Task): Promise<Task>;
88
88
  onError(err: any, queueName: string, task: Task): Promise<Task>;
89
89
  onBatchError(err: any, queueName: string, tasks: Array<[string, any, number, string, string, number]>): Promise<void>;
package/dist/index.d.ts CHANGED
@@ -83,7 +83,7 @@ declare class PowerQueues extends PowerRedis {
83
83
  private payloadBatch;
84
84
  beforeExecute(queueName: string, tasks: Array<[string, any, number, string, string, number]>): Promise<[string, any, number, string, string, number][]>;
85
85
  onExecute(queueName: string, task: Task): Promise<Task>;
86
- onBatchReady(queueName: string, tasks: Array<Task>): Promise<void>;
86
+ onBatchReady(queueName: string, tasks: Task[]): Promise<void>;
87
87
  onSuccess(queueName: string, task: Task): Promise<Task>;
88
88
  onError(err: any, queueName: string, task: Task): Promise<Task>;
89
89
  onBatchError(err: any, queueName: string, tasks: Array<[string, any, number, string, string, number]>): Promise<void>;
package/dist/index.js CHANGED
@@ -258,7 +258,7 @@ var PowerQueues = class extends PowerRedis {
258
258
  this.selectStuckTimeout = 6e4;
259
259
  this.selectStuckMaxTimeout = 80;
260
260
  this.selectCount = 200;
261
- this.selectTimeout = 5e3;
261
+ this.selectTimeout = 3e3;
262
262
  this.buildBatchCount = 800;
263
263
  this.buildBatchMaxCount = 1e4;
264
264
  this.retryCount = 1;
@@ -266,7 +266,7 @@ var PowerQueues = class extends PowerRedis {
266
266
  this.idemLockTimeout = 18e4;
267
267
  this.idemDoneTimeout = 6e4;
268
268
  this.logStatus = false;
269
- this.logStatusTimeout = 6e5;
269
+ this.logStatusTimeout = 18e5;
270
270
  this.approveCount = 2e3;
271
271
  this.removeOnExecuted = true;
272
272
  }
@@ -322,17 +322,26 @@ var PowerQueues = class extends PowerRedis {
322
322
  if (!filtered[key]) {
323
323
  filtered[key] = [];
324
324
  }
325
- filtered[key].push(tasks[index]);
325
+ filtered[key].push(tasks[index][1]);
326
326
  });
327
327
  for (let key in filtered) {
328
328
  const filteredTasks = filtered[key];
329
329
  const keySplit = key.split(":");
330
330
  const attempt = Number(keySplit[0]);
331
- await this.addTasks(queueName + (attempt >= this.retryCount - 1 ? ":dlq" : ""), filteredTasks.map((task) => ({ ...task[1] })), {
332
- createdAt: Number(keySplit[1]),
333
- job: keySplit[2],
334
- attempt: attempt + 1
335
- });
331
+ const job = String(keySplit[2]);
332
+ if (!(attempt >= this.retryCount - 1)) {
333
+ await this.addTasks(queueName, filteredTasks, {
334
+ job,
335
+ attempt: attempt + 1
336
+ });
337
+ } else if (this.logStatus) {
338
+ const statusKey = `${queueName}:${job}:`;
339
+ await this.setOne(statusKey + "err", Number(await this.getOne(statusKey + "err") || 0) + filteredTasks.length, this.logStatusTimeout);
340
+ await this.setOne(statusKey + "ready", Number(await this.getOne(statusKey + "ready") || 0) + filteredTasks.length, this.logStatusTimeout);
341
+ await this.addTasks(queueName + ":dlq", filteredTasks, {
342
+ job
343
+ });
344
+ }
336
345
  }
337
346
  } catch (err2) {
338
347
  throw new Error(`Batch error. ${err2.message}`);
@@ -452,8 +461,9 @@ var PowerQueues = class extends PowerRedis {
452
461
  }
453
462
  }
454
463
  }
464
+ let start = Date.now();
455
465
  if (!this.executeSync && promises.length > 0) {
456
- await Promise.all(promises.map((item) => item));
466
+ await Promise.all(promises.map((item) => item()));
457
467
  }
458
468
  await this.onBatchReady(queueName, result);
459
469
  if (!isArrFilled(result) && contended > tasks.length >> 1) {
@@ -532,26 +542,24 @@ var PowerQueues = class extends PowerRedis {
532
542
  return await this.onSuccess(queueName, task);
533
543
  }
534
544
  async error(err, queueName, task) {
535
- const dlqKey = queueName + ":dlq";
536
545
  const taskP = { ...task };
537
- if (taskP.attempt >= this.retryCount - 1) {
538
- const statusKey = `${queueName}:${taskP.job}:`;
539
- if (this.logStatus) {
540
- await this.incr(statusKey + "err", this.logStatusTimeout);
541
- await this.incr(statusKey + "ready", this.logStatusTimeout);
542
- }
543
- await this.addTasks(dlqKey, [{ ...taskP.payload }], {
544
- createdAt: taskP.createdAt,
545
- job: taskP.job,
546
- attempt: taskP.attempt
547
- });
548
- } else {
546
+ if (!(taskP.attempt >= this.retryCount - 1)) {
549
547
  await this.onRetry(err, queueName, taskP);
550
548
  await this.addTasks(queueName, [{ ...taskP.payload }], {
551
549
  createdAt: taskP.createdAt,
552
550
  job: taskP.job,
553
551
  attempt: (taskP.attempt || 0) + 1
554
552
  });
553
+ } else if (this.logStatus) {
554
+ const dlqKey = queueName + ":dlq";
555
+ const statusKey = `${queueName}:${taskP.job}:`;
556
+ await this.incr(statusKey + "err", this.logStatusTimeout);
557
+ await this.incr(statusKey + "ready", this.logStatusTimeout);
558
+ await this.addTasks(dlqKey, [{ ...taskP.payload }], {
559
+ createdAt: taskP.createdAt,
560
+ job: taskP.job,
561
+ attempt: taskP.attempt
562
+ });
555
563
  }
556
564
  return await this.onError(err, queueName, { ...taskP, attempt: (taskP.attempt || 0) + 1 });
557
565
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "power-queues",
3
- "version": "2.1.3",
3
+ "version": "2.1.4",
4
4
  "description": "High-performance Redis Streams queue for Node.js with Lua-powered bulk XADD, idempotent workers, heartbeat locks, stuck-task recovery, retries, DLQ, and distributed processing.",
5
5
  "author": "ihor-bielchenko",
6
6
  "license": "MIT",