@hastehaul/common 2.0.53 → 2.1.0

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.
@@ -109,8 +109,16 @@ class NatsConsumer {
109
109
  }
110
110
  }
111
111
  catch (error) {
112
- console.error("Consumer Error: ", error);
113
- throw new Error("Failed to consume messages");
112
+ switch (error.code) {
113
+ case nats_1.ErrorCode.NoResponders:
114
+ console.error("Consumer Error: no one is listening");
115
+ break;
116
+ case nats_1.ErrorCode.Timeout:
117
+ console.error("Consumer Error: someone is listening but didn't respond");
118
+ break;
119
+ default:
120
+ console.error("Consumer Error: request failed", error);
121
+ }
114
122
  }
115
123
  });
116
124
  }
@@ -9,7 +9,7 @@ export declare abstract class AbstractWorker {
9
9
  *
10
10
  * @param {string} queueName - The name of the job queue that this worker will process jobs from.
11
11
  */
12
- constructor(queueName: string);
12
+ constructor(queueName: string, useReplicas?: boolean);
13
13
  /**
14
14
  * Abstract method to process jobs retrieved from the job queue.
15
15
  *
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AbstractWorker = void 0;
4
4
  const bullmq_1 = require("bullmq");
5
- // import { redisWrapper } from '../../../connections-wrappers/redis-connection-wrapper';
5
+ const redis_connection_wrapper_1 = require("../../../connections-wrappers/redis-connection-wrapper");
6
6
  const redis_wrapper_1 = require("../../../connections-wrappers/redis-wrapper");
7
7
  /**
8
8
  * Abstract class representing a worker for processing jobs from a Job Queue.
@@ -13,10 +13,10 @@ class AbstractWorker {
13
13
  *
14
14
  * @param {string} queueName - The name of the job queue that this worker will process jobs from.
15
15
  */
16
- constructor(queueName) {
16
+ constructor(queueName, useReplicas = true) {
17
17
  // Create a worker instance with the provided queueName and bind the 'process' method to this worker.
18
18
  this.worker = new bullmq_1.Worker(queueName, this.process.bind(this), {
19
- connection: redis_wrapper_1.rWrapper.masterClient,
19
+ connection: useReplicas ? redis_wrapper_1.rWrapper.masterClient : redis_connection_wrapper_1.redisWrapper.client,
20
20
  autorun: false,
21
21
  prefix: '{BULLMQ}',
22
22
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hastehaul/common",
3
- "version": "2.0.53",
3
+ "version": "2.1.0",
4
4
  "description": "",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",