@seidor-cloud-produtos/orbit-backend-lib 2.0.21 → 2.0.23

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.
@@ -2,12 +2,15 @@ import Handler from '../../../clean-arch/application/queue/handler';
2
2
  import AmqpQueue from '../queue/rabbitmq/amqp-lib';
3
3
  import { AmqpQueueGetResult } from '../queue/rabbitmq/types';
4
4
  import { RabbitMQScaledJobOptions } from './types';
5
+ export interface IRunnerOptions extends Partial<RabbitMQScaledJobOptions> {
6
+ }
5
7
  export declare class RabbitMQScaledJobRunner<T = any> {
6
8
  private readonly amqpQueue;
7
9
  private readonly queueName;
8
10
  private readonly handler;
9
11
  private readonly options;
10
- constructor(amqpQueue: AmqpQueue, queueName: string, handler: Handler, options: RabbitMQScaledJobOptions);
12
+ constructor(amqpQueue: AmqpQueue, queueName: string, handler: Handler, options?: IRunnerOptions);
13
+ private setOptions;
11
14
  private handleError;
12
15
  protected errorStrategy(getResult: AmqpQueueGetResult): Promise<void>;
13
16
  private rejectTimeout;
@@ -12,7 +12,14 @@ class RabbitMQScaledJobRunner {
12
12
  this.amqpQueue = amqpQueue;
13
13
  this.queueName = queueName;
14
14
  this.handler = handler;
15
- this.options = options;
15
+ this.setOptions(options);
16
+ }
17
+ setOptions(options) {
18
+ this.options.errorStrategy = options?.errorStrategy || 'nack-dlq';
19
+ this.options.manualAck = options?.manualAck || true;
20
+ this.options.parse =
21
+ options?.parse || (raw => JSON.parse(raw.content.toString()));
22
+ this.options.timeoutMs = options?.timeoutMs || 10000;
16
23
  }
17
24
  async handleError(error, getResult) {
18
25
  if (!getResult) {
@@ -41,7 +48,7 @@ class RabbitMQScaledJobRunner {
41
48
  async run() {
42
49
  let getResult = null;
43
50
  let consumedMessages = 0;
44
- const messagesToGet = this.options.numberOfMessagesToGet ?? 1;
51
+ const messagesToGet = this.handler.getSimultaneity();
45
52
  try {
46
53
  while (consumedMessages < messagesToGet) {
47
54
  try {
@@ -1,8 +1,7 @@
1
- export type ErrorStrategy = "nack-dlq" | "nack-requeue";
1
+ export type ErrorStrategy = 'nack-dlq' | 'nack-requeue';
2
2
  export type RabbitMQScaledJobOptions = {
3
3
  parse: (raw: any) => any;
4
4
  manualAck: boolean;
5
5
  errorStrategy: ErrorStrategy;
6
6
  timeoutMs: number;
7
- numberOfMessagesToGet?: number;
8
7
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seidor-cloud-produtos/orbit-backend-lib",
3
- "version": "2.0.21",
3
+ "version": "2.0.23",
4
4
  "description": "Internal lib for backend components",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",