@jetit/publisher 2.0.0 → 2.0.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jetit/publisher",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "type": "commonjs",
5
5
  "dependencies": {
6
6
  "@jetit/id": "0.0.11",
@@ -8,7 +8,7 @@
8
8
  "rxjs": "^7.8.0"
9
9
  },
10
10
  "peerDependencies": {
11
- "tslib": "^2.3.0"
11
+ "tslib": "2.5.0"
12
12
  },
13
13
  "main": "./src/index.js",
14
14
  "types": "./src/index.d.ts"
@@ -5,6 +5,8 @@ export declare class RedisRegistry {
5
5
  private static registry;
6
6
  private static options;
7
7
  static attemptConnection(connectionKey: string, storeRef?: number): RedisType;
8
+ static handleDisconnects(connection: RedisType, connectionKey: string, storeRef: number): void;
9
+ static handlePing(connection: RedisType): void;
8
10
  static getConnection(connectionType?: string, storeRef?: number): RedisType;
9
11
  static setOptions(options: IOptions): void;
10
12
  static _getOptions(): IOptions;
@@ -2,6 +2,7 @@
2
2
  var _a, _b;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.setRedisConnectionSettings = exports.RedisRegistry = void 0;
5
+ const tslib_1 = require("tslib");
5
6
  const ioredis_1 = require("ioredis");
6
7
  class RedisRegistry {
7
8
  static attemptConnection(connectionKey, storeRef = 0) {
@@ -12,8 +13,33 @@ class RedisRegistry {
12
13
  else
13
14
  ref = new ioredis_1.default(Object.assign(Object.assign({}, RedisRegistry.options.redis), { db: storeRef }));
14
15
  RedisRegistry.registry.set(connectionKey, ref);
16
+ RedisRegistry.handleDisconnects(ref, connectionKey, storeRef);
15
17
  return ref;
16
18
  }
19
+ static handleDisconnects(connection, connectionKey, storeRef) {
20
+ connection.on('error', (error) => {
21
+ console.error(`PUBLISHER: Redis connection error : ${error.message}`);
22
+ connection.removeAllListeners();
23
+ RedisRegistry.attemptConnection(connectionKey, storeRef);
24
+ });
25
+ }
26
+ static handlePing(connection) {
27
+ setInterval(() => tslib_1.__awaiter(this, void 0, void 0, function* () {
28
+ const res = yield Promise.race([
29
+ connection.ping(),
30
+ new Promise((res) => {
31
+ setTimeout(() => {
32
+ res('NO_PING');
33
+ }, 1000);
34
+ }),
35
+ ]);
36
+ if (res === 'NO_PING') {
37
+ connection.disconnect(true);
38
+ console.error('PUBLISHER: failed to ping redis, disconnecting and restarting service.');
39
+ process.exit(0);
40
+ }
41
+ }), 2000);
42
+ }
17
43
  static getConnection(connectionType = 'primary', storeRef = 0) {
18
44
  const connectionKey = `${connectionType}${storeRef}`;
19
45
  let ref = this.registry.get(connectionKey);
@@ -214,7 +214,7 @@ class Streams {
214
214
  const streamName = `${eventName}:${this.consumerGroupName}`;
215
215
  const processMessage = (redisClient) => tslib_1.__awaiter(this, void 0, void 0, function* () {
216
216
  const racePr = new Promise((resolve, _) => {
217
- setTimeout(resolve, 1100, 'RACE');
217
+ setTimeout(resolve, 1300, 'RACE');
218
218
  });
219
219
  console.log(`PUBLISHER: processMessage called for ${streamName} cgn: ${this.consumerGroupName} inst: ${this.instanceId}`);
220
220
  try {