power-queues 2.1.4 → 2.1.5

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
@@ -25,6 +25,7 @@ __export(index_exports, {
25
25
  module.exports = __toCommonJS(index_exports);
26
26
 
27
27
  // src/PowerQueues.ts
28
+ var import_node_events = require("events");
28
29
  var import_power_redis = require("power-redis");
29
30
  var import_full_utils = require("full-utils");
30
31
  var import_uuid = require("uuid");
@@ -294,6 +295,7 @@ var PowerQueues = class extends import_power_redis.PowerRedis {
294
295
  return this.host + ":" + process.pid;
295
296
  }
296
297
  async runQueue(queueName, from = "0-0") {
298
+ (0, import_node_events.setMaxListeners)(0, this.abort.signal);
297
299
  await this.createGroup(queueName, from);
298
300
  await this.consumerLoop(queueName, from);
299
301
  }
@@ -624,22 +626,21 @@ var PowerQueues = class extends import_power_redis.PowerRedis {
624
626
  return;
625
627
  }
626
628
  const workerHeartbeatTimeoutMs = Math.max(1e3, Math.floor(Math.max(5e3, this.idemLockTimeout | 0) / 4));
627
- let timer;
628
- let alive = true;
629
- let hbFails = 0;
629
+ let timer, alive = true, hbFails = 0;
630
630
  const stop = () => {
631
631
  alive = false;
632
632
  if (timer) {
633
633
  clearTimeout(timer);
634
634
  }
635
635
  };
636
- const signal = this.signal();
637
- const onAbort = () => stop();
638
- signal?.addEventListener?.("abort", onAbort, { once: true });
639
636
  const tick = async () => {
640
637
  if (!alive) {
641
638
  return;
642
639
  }
640
+ if (this.signal()?.aborted) {
641
+ stop();
642
+ return;
643
+ }
643
644
  try {
644
645
  const ok = await this.sendHeartbeat(keys);
645
646
  hbFails = ok ? 0 : hbFails + 1;
@@ -658,10 +659,7 @@ var PowerQueues = class extends import_power_redis.PowerRedis {
658
659
  };
659
660
  timer = setTimeout(tick, workerHeartbeatTimeoutMs);
660
661
  timer.unref?.();
661
- return () => {
662
- signal?.removeEventListener?.("abort", onAbort);
663
- stop();
664
- };
662
+ return () => stop();
665
663
  }
666
664
  async runScript(name, keys, args, defaultCode) {
667
665
  if (!this.scripts[name]) {
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  // src/PowerQueues.ts
2
+ import { setMaxListeners } from "events";
2
3
  import { PowerRedis } from "power-redis";
3
4
  import {
4
5
  isObjFilled,
@@ -277,6 +278,7 @@ var PowerQueues = class extends PowerRedis {
277
278
  return this.host + ":" + process.pid;
278
279
  }
279
280
  async runQueue(queueName, from = "0-0") {
281
+ setMaxListeners(0, this.abort.signal);
280
282
  await this.createGroup(queueName, from);
281
283
  await this.consumerLoop(queueName, from);
282
284
  }
@@ -607,22 +609,21 @@ var PowerQueues = class extends PowerRedis {
607
609
  return;
608
610
  }
609
611
  const workerHeartbeatTimeoutMs = Math.max(1e3, Math.floor(Math.max(5e3, this.idemLockTimeout | 0) / 4));
610
- let timer;
611
- let alive = true;
612
- let hbFails = 0;
612
+ let timer, alive = true, hbFails = 0;
613
613
  const stop = () => {
614
614
  alive = false;
615
615
  if (timer) {
616
616
  clearTimeout(timer);
617
617
  }
618
618
  };
619
- const signal = this.signal();
620
- const onAbort = () => stop();
621
- signal?.addEventListener?.("abort", onAbort, { once: true });
622
619
  const tick = async () => {
623
620
  if (!alive) {
624
621
  return;
625
622
  }
623
+ if (this.signal()?.aborted) {
624
+ stop();
625
+ return;
626
+ }
626
627
  try {
627
628
  const ok = await this.sendHeartbeat(keys);
628
629
  hbFails = ok ? 0 : hbFails + 1;
@@ -641,10 +642,7 @@ var PowerQueues = class extends PowerRedis {
641
642
  };
642
643
  timer = setTimeout(tick, workerHeartbeatTimeoutMs);
643
644
  timer.unref?.();
644
- return () => {
645
- signal?.removeEventListener?.("abort", onAbort);
646
- stop();
647
- };
645
+ return () => stop();
648
646
  }
649
647
  async runScript(name, keys, args, defaultCode) {
650
648
  if (!this.scripts[name]) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "power-queues",
3
- "version": "2.1.4",
3
+ "version": "2.1.5",
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",