@jetit/publisher 1.0.8 → 1.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.
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@jetit/publisher",
3
- "version": "1.0.8",
3
+ "version": "1.1.0",
4
4
  "type": "commonjs",
5
5
  "dependencies": {
6
- "@jetit/id": "0.0.6",
6
+ "@jetit/id": "0.0.11",
7
7
  "ioredis": "5.3.1",
8
- "rxjs": "7.8.0"
8
+ "rxjs": "7.8.0",
9
+ "tslib": "2.5.0"
9
10
  },
10
11
  "peerDependencies": {
11
- "@types/ioredis-mock": "8.2.1",
12
- "tslib": "2.5.0"
12
+ "@types/ioredis-mock": "8.2.1"
13
13
  },
14
14
  "main": "./src/index.js",
15
15
  "types": "./src/index.d.ts"
@@ -42,13 +42,13 @@ class Streams {
42
42
  this.instanceId = `${serviceName}:${(0, id_1.generateID)('HEX', 'FE')}`;
43
43
  this.consumerGroupName = `cg-${serviceName}`;
44
44
  const cleanUpInterval = (_a = parseInt(process.env['CLEANUP_INTERVAL'] || '1000 * 60 * 60', 10)) !== null && _a !== void 0 ? _a : 1000 * 60 * 60;
45
- this.cleanUpTimer = (0, rxjs_1.interval)(cleanUpInterval).subscribe(() => {
45
+ this.cleanUpTimer = setInterval(() => {
46
46
  this.clearDuplicationCheckKeys();
47
- this.eventsListened.forEach((eventName) => {
47
+ for (const eventName of this.eventsListened) {
48
48
  this.cleanupAcknowledgedMessages(eventName, cleanUpInterval);
49
49
  this.republishUnprocessedEvents(eventName);
50
- });
51
- });
50
+ }
51
+ }, cleanUpInterval);
52
52
  }
53
53
  createConsumerGroup(eventName) {
54
54
  return tslib_1.__awaiter(this, void 0, void 0, function* () {
@@ -258,15 +258,16 @@ class Streams {
258
258
  const result = yield this.redisGroups.xreadgroup('GROUP', this.consumerGroupName, this.instanceId, 'STREAMS', streamName, '>');
259
259
  if (result) {
260
260
  const [, streamMessages] = result[0];
261
+ console.log(`Unprocessed events: ${streamMessages.length}`);
261
262
  for (const [id, data] of streamMessages) {
262
263
  const eventData = JSON.parse(data[1]);
263
- console.log(`Unprocessed event: ${id}, data:`, eventData);
264
264
  const transaction = this.redisGroups.multi();
265
265
  // Republishing the events
266
266
  transaction.xadd(streamName, '*', 'data', JSON.stringify(eventData));
267
267
  transaction.publish(eventName, '');
268
268
  transaction.xack(streamName, this.consumerGroupName, id);
269
269
  yield transaction.exec();
270
+ console.log(`Event ${eventName} with ID: ${id} published`);
270
271
  }
271
272
  }
272
273
  });
@@ -344,7 +345,7 @@ class Streams {
344
345
  yield this.redisGroups.quit();
345
346
  }
346
347
  if (this.cleanUpTimer) {
347
- this.cleanUpTimer.unsubscribe();
348
+ clearInterval(this.cleanUpTimer);
348
349
  }
349
350
  });
350
351
  }