power-queues 2.0.7 → 2.0.9

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
@@ -290,6 +290,12 @@ var PowerQueues = class extends import_power_redis.PowerRedis {
290
290
  }
291
291
  async onSuccess(id, payload, createdAt, job, key) {
292
292
  }
293
+ async onBatchError(err, tasks) {
294
+ }
295
+ async onError(err, id, payload, createdAt, job, key) {
296
+ }
297
+ async onRetry(err, id, payload, createdAt, job, key, attempts) {
298
+ }
293
299
  async runQueue() {
294
300
  await this.createGroup("0-0");
295
301
  await this.consumerLoop();
@@ -538,26 +544,25 @@ var PowerQueues = class extends import_power_redis.PowerRedis {
538
544
  }
539
545
  async success(id, payload, createdAt, job, key) {
540
546
  if (this.executeJobStatus) {
541
- await this.status(id, payload, createdAt, job, key);
547
+ const prefix = `${this.stream}:${job}:`;
548
+ const { ready = 0, ok = 0 } = await this.getMany(`${prefix}*`);
549
+ await this.setMany([{ key: `${prefix}ready`, value: ready + 1 }, { key: `${prefix}ok`, value: ok + 1 }], this.executeJobStatusTtlSec);
542
550
  }
543
551
  await this.onSuccess(id, payload, createdAt, job, key);
544
552
  }
545
- async status(id, payload, createdAt, job, key) {
546
- const prefix = `s:${this.stream}:`;
547
- const { ready = 0, ok = 0 } = await this.getMany(prefix);
548
- await this.setMany([{ key: `${prefix}ready`, value: ready + 1 }, { key: `${prefix}ok`, value: ok + 1 }], this.executeJobStatusTtlSec);
549
- }
550
553
  async batchError(err, tasks) {
554
+ await this.onBatchError(err, tasks);
551
555
  }
552
- async error(err, id, payload, createdAt, job, key) {
556
+ async error(err, id, payload, createdAt, job, key, attempt) {
557
+ if (this.executeJobStatus && attempt >= this.workerMaxRetries) {
558
+ const prefix = `${this.stream}:${job}:`;
559
+ const { ready = 0, err: err2 = 0 } = await this.getMany(`${prefix}*`);
560
+ await this.setMany([{ key: `${prefix}ready`, value: ready + 1 }, { key: `${prefix}err`, value: err2 + 1 }], this.executeJobStatusTtlSec);
561
+ }
553
562
  await this.onError(err, id, payload, createdAt, job, key);
554
563
  }
555
- async onError(err, id, payload, createdAt, job, key) {
556
- }
557
- async attempt(err, id, payload, createdAt, job, key, attempts) {
558
- await this.onRetry(err, id, payload, createdAt, job, key, attempts);
559
- }
560
- async onRetry(err, id, payload, createdAt, job, key, attempts) {
564
+ async attempt(err, id, payload, createdAt, job, key, attempt) {
565
+ await this.onRetry(err, id, payload, createdAt, job, key, attempt);
561
566
  }
562
567
  async execute(tasks) {
563
568
  const result = [];
@@ -603,10 +608,10 @@ var PowerQueues = class extends import_power_redis.PowerRedis {
603
608
  await this.success(id, payload, createdAt, job, key);
604
609
  return { id };
605
610
  } catch (err) {
606
- const attempts = await this.incrAttempts(id);
607
- await this.attempt(err, id, payload, createdAt, job, key, attempts);
608
- await this.error(err, id, payload, createdAt, job, key);
609
- if (attempts >= this.workerMaxRetries) {
611
+ const attempt = await this.incrAttempts(id);
612
+ await this.attempt(err, id, payload, createdAt, job, key, attempt);
613
+ await this.error(err, id, payload, createdAt, job, key, attempt);
614
+ if (attempt >= this.workerMaxRetries) {
610
615
  await this.addTasks(`${this.stream}:dlq`, [{
611
616
  payload: {
612
617
  ...payload,
@@ -614,7 +619,7 @@ var PowerQueues = class extends import_power_redis.PowerRedis {
614
619
  createdAt,
615
620
  job,
616
621
  id,
617
- attempts
622
+ attempt
618
623
  }
619
624
  }]);
620
625
  await this.clearAttempts(id);
@@ -664,11 +669,11 @@ var PowerQueues = class extends import_power_redis.PowerRedis {
664
669
  await this.success(id, payload, createdAt, job, key);
665
670
  return { id };
666
671
  } catch (err) {
667
- const attempts = await this.incrAttempts(id);
672
+ const attempt = await this.incrAttempts(id);
668
673
  try {
669
- await this.attempt(err, id, payload, createdAt, job, key, attempts);
670
- await this.error(err, id, payload, createdAt, job, key);
671
- if (attempts >= this.workerMaxRetries) {
674
+ await this.attempt(err, id, payload, createdAt, job, key, attempt);
675
+ await this.error(err, id, payload, createdAt, job, key, attempt);
676
+ if (attempt >= this.workerMaxRetries) {
672
677
  await this.addTasks(`${this.stream}:dlq`, [{
673
678
  payload: {
674
679
  ...payload,
package/dist/index.d.cts CHANGED
@@ -58,6 +58,9 @@ declare class PowerQueues extends PowerRedis {
58
58
  onExecute(id: string, payload: any, createdAt: number, job: string, key: string, attempt: number): Promise<void>;
59
59
  onExecuted(data: Array<[string, any[], number, string, string]>): Promise<void>;
60
60
  onSuccess(id: string, payload: any, createdAt: number, job: string, key: string): Promise<void>;
61
+ onBatchError(err: any, tasks?: Array<[string, any[], number, string, string]>): Promise<void>;
62
+ onError(err: any, id: string, payload: any, createdAt: number, job: string, key: string): Promise<void>;
63
+ onRetry(err: any, id: string, payload: any, createdAt: number, job: string, key: string, attempts: number): Promise<void>;
61
64
  runQueue(): Promise<void>;
62
65
  consumerLoop(): Promise<void>;
63
66
  addTasks(queueName: string, data: any[], opts?: AddTasksOptions): Promise<string[]>;
@@ -74,12 +77,9 @@ declare class PowerQueues extends PowerRedis {
74
77
  private getAttempts;
75
78
  private clearAttempts;
76
79
  private success;
77
- private status;
78
80
  private batchError;
79
81
  private error;
80
- onError(err: any, id: string, payload: any, createdAt: number, job: string, key: string): Promise<void>;
81
82
  private attempt;
82
- onRetry(err: any, id: string, payload: any, createdAt: number, job: string, key: string, attempts: number): Promise<void>;
83
83
  private execute;
84
84
  private executeProcess;
85
85
  private approve;
package/dist/index.d.ts CHANGED
@@ -58,6 +58,9 @@ declare class PowerQueues extends PowerRedis {
58
58
  onExecute(id: string, payload: any, createdAt: number, job: string, key: string, attempt: number): Promise<void>;
59
59
  onExecuted(data: Array<[string, any[], number, string, string]>): Promise<void>;
60
60
  onSuccess(id: string, payload: any, createdAt: number, job: string, key: string): Promise<void>;
61
+ onBatchError(err: any, tasks?: Array<[string, any[], number, string, string]>): Promise<void>;
62
+ onError(err: any, id: string, payload: any, createdAt: number, job: string, key: string): Promise<void>;
63
+ onRetry(err: any, id: string, payload: any, createdAt: number, job: string, key: string, attempts: number): Promise<void>;
61
64
  runQueue(): Promise<void>;
62
65
  consumerLoop(): Promise<void>;
63
66
  addTasks(queueName: string, data: any[], opts?: AddTasksOptions): Promise<string[]>;
@@ -74,12 +77,9 @@ declare class PowerQueues extends PowerRedis {
74
77
  private getAttempts;
75
78
  private clearAttempts;
76
79
  private success;
77
- private status;
78
80
  private batchError;
79
81
  private error;
80
- onError(err: any, id: string, payload: any, createdAt: number, job: string, key: string): Promise<void>;
81
82
  private attempt;
82
- onRetry(err: any, id: string, payload: any, createdAt: number, job: string, key: string, attempts: number): Promise<void>;
83
83
  private execute;
84
84
  private executeProcess;
85
85
  private approve;
package/dist/index.js CHANGED
@@ -264,6 +264,12 @@ var PowerQueues = class extends PowerRedis {
264
264
  }
265
265
  async onSuccess(id, payload, createdAt, job, key) {
266
266
  }
267
+ async onBatchError(err, tasks) {
268
+ }
269
+ async onError(err, id, payload, createdAt, job, key) {
270
+ }
271
+ async onRetry(err, id, payload, createdAt, job, key, attempts) {
272
+ }
267
273
  async runQueue() {
268
274
  await this.createGroup("0-0");
269
275
  await this.consumerLoop();
@@ -512,26 +518,25 @@ var PowerQueues = class extends PowerRedis {
512
518
  }
513
519
  async success(id, payload, createdAt, job, key) {
514
520
  if (this.executeJobStatus) {
515
- await this.status(id, payload, createdAt, job, key);
521
+ const prefix = `${this.stream}:${job}:`;
522
+ const { ready = 0, ok = 0 } = await this.getMany(`${prefix}*`);
523
+ await this.setMany([{ key: `${prefix}ready`, value: ready + 1 }, { key: `${prefix}ok`, value: ok + 1 }], this.executeJobStatusTtlSec);
516
524
  }
517
525
  await this.onSuccess(id, payload, createdAt, job, key);
518
526
  }
519
- async status(id, payload, createdAt, job, key) {
520
- const prefix = `s:${this.stream}:`;
521
- const { ready = 0, ok = 0 } = await this.getMany(prefix);
522
- await this.setMany([{ key: `${prefix}ready`, value: ready + 1 }, { key: `${prefix}ok`, value: ok + 1 }], this.executeJobStatusTtlSec);
523
- }
524
527
  async batchError(err, tasks) {
528
+ await this.onBatchError(err, tasks);
525
529
  }
526
- async error(err, id, payload, createdAt, job, key) {
530
+ async error(err, id, payload, createdAt, job, key, attempt) {
531
+ if (this.executeJobStatus && attempt >= this.workerMaxRetries) {
532
+ const prefix = `${this.stream}:${job}:`;
533
+ const { ready = 0, err: err2 = 0 } = await this.getMany(`${prefix}*`);
534
+ await this.setMany([{ key: `${prefix}ready`, value: ready + 1 }, { key: `${prefix}err`, value: err2 + 1 }], this.executeJobStatusTtlSec);
535
+ }
527
536
  await this.onError(err, id, payload, createdAt, job, key);
528
537
  }
529
- async onError(err, id, payload, createdAt, job, key) {
530
- }
531
- async attempt(err, id, payload, createdAt, job, key, attempts) {
532
- await this.onRetry(err, id, payload, createdAt, job, key, attempts);
533
- }
534
- async onRetry(err, id, payload, createdAt, job, key, attempts) {
538
+ async attempt(err, id, payload, createdAt, job, key, attempt) {
539
+ await this.onRetry(err, id, payload, createdAt, job, key, attempt);
535
540
  }
536
541
  async execute(tasks) {
537
542
  const result = [];
@@ -577,10 +582,10 @@ var PowerQueues = class extends PowerRedis {
577
582
  await this.success(id, payload, createdAt, job, key);
578
583
  return { id };
579
584
  } catch (err) {
580
- const attempts = await this.incrAttempts(id);
581
- await this.attempt(err, id, payload, createdAt, job, key, attempts);
582
- await this.error(err, id, payload, createdAt, job, key);
583
- if (attempts >= this.workerMaxRetries) {
585
+ const attempt = await this.incrAttempts(id);
586
+ await this.attempt(err, id, payload, createdAt, job, key, attempt);
587
+ await this.error(err, id, payload, createdAt, job, key, attempt);
588
+ if (attempt >= this.workerMaxRetries) {
584
589
  await this.addTasks(`${this.stream}:dlq`, [{
585
590
  payload: {
586
591
  ...payload,
@@ -588,7 +593,7 @@ var PowerQueues = class extends PowerRedis {
588
593
  createdAt,
589
594
  job,
590
595
  id,
591
- attempts
596
+ attempt
592
597
  }
593
598
  }]);
594
599
  await this.clearAttempts(id);
@@ -638,11 +643,11 @@ var PowerQueues = class extends PowerRedis {
638
643
  await this.success(id, payload, createdAt, job, key);
639
644
  return { id };
640
645
  } catch (err) {
641
- const attempts = await this.incrAttempts(id);
646
+ const attempt = await this.incrAttempts(id);
642
647
  try {
643
- await this.attempt(err, id, payload, createdAt, job, key, attempts);
644
- await this.error(err, id, payload, createdAt, job, key);
645
- if (attempts >= this.workerMaxRetries) {
648
+ await this.attempt(err, id, payload, createdAt, job, key, attempt);
649
+ await this.error(err, id, payload, createdAt, job, key, attempt);
650
+ if (attempt >= this.workerMaxRetries) {
646
651
  await this.addTasks(`${this.stream}:dlq`, [{
647
652
  payload: {
648
653
  ...payload,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "power-queues",
3
- "version": "2.0.7",
3
+ "version": "2.0.9",
4
4
  "description": "Base classes for implementing custom queues in redis under high load conditions based on nestjs.",
5
5
  "author": "ihor-bielchenko",
6
6
  "license": "MIT",