@imqueue/core 2.0.11 → 2.0.14

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": "@imqueue/core",
3
- "version": "2.0.11",
3
+ "version": "2.0.14",
4
4
  "description": "Simple JSON-based messaging queue for inter service communication",
5
5
  "keywords": [
6
6
  "message-queue",
@@ -75,7 +75,7 @@ export declare class ClusteredRedisQueue implements IMessageQueue, EventEmitter<
75
75
  *
76
76
  * @type {number}
77
77
  */
78
- private queueLength;
78
+ private imqLength;
79
79
  /**
80
80
  * Template EventEmitter instance used to replicate queue EventEmitters when
81
81
  * dynamically modifying the cluster
@@ -143,6 +143,7 @@ export declare class ClusteredRedisQueue implements IMessageQueue, EventEmitter<
143
143
  * @returns {Promise<ClusteredRedisQueue>}
144
144
  */
145
145
  clear(): Promise<ClusteredRedisQueue>;
146
+ queueLength(): Promise<number>;
146
147
  /**
147
148
  * Batch imq action processing on all registered imqs at once
148
149
  *
@@ -75,7 +75,7 @@ class ClusteredRedisQueue {
75
75
  *
76
76
  * @type {number}
77
77
  */
78
- this.queueLength = 0;
78
+ this.imqLength = 0;
79
79
  this.state = {
80
80
  started: false,
81
81
  subscription: null,
@@ -139,12 +139,12 @@ class ClusteredRedisQueue {
139
139
  * @returns {Promise<string>} - message identifier
140
140
  */
141
141
  async send(toQueue, message, delay, errorHandler) {
142
- if (!this.queueLength) {
142
+ if (!this.imqLength) {
143
143
  return await new Promise(resolve => this.clusterEmitter.once('initialized', async ({ imq }) => {
144
144
  resolve(await imq.send(toQueue, message, delay, errorHandler));
145
145
  }));
146
146
  }
147
- if (this.currentQueue >= this.queueLength) {
147
+ if (this.currentQueue >= this.imqLength) {
148
148
  this.currentQueue = 0;
149
149
  }
150
150
  const imq = this.imqs[this.currentQueue];
@@ -207,6 +207,14 @@ class ClusteredRedisQueue {
207
207
  async clear() {
208
208
  return await this.batch('clear', 'Clearing clustered redis message queue...');
209
209
  }
210
+ async queueLength() {
211
+ const promises = [];
212
+ for (const imq of this.imqs) {
213
+ promises.push(imq.queueLength());
214
+ }
215
+ const lengths = await Promise.all(promises);
216
+ return lengths.reduce((total, length) => total + length, 0);
217
+ }
210
218
  /**
211
219
  * Batch imq action processing on all registered imqs at once
212
220
  *
@@ -376,7 +384,7 @@ class ClusteredRedisQueue {
376
384
  this.imqs = this.imqs.filter(imq => imqToRemove.redisKey !== imq.redisKey);
377
385
  imqToRemove.destroy().catch();
378
386
  }
379
- this.queueLength = this.imqs.length;
387
+ this.imqLength = this.imqs.length;
380
388
  this.servers = this.servers.filter(existing => !ClusteredRedisQueue.matchServers(existing, server));
381
389
  this.clusterEmitter.emit('remove', {
382
390
  server: remove,
@@ -407,7 +415,7 @@ class ClusteredRedisQueue {
407
415
  this.imqs.push(imq);
408
416
  this.servers.push(newServer);
409
417
  this.clusterEmitter.emit('add', { server: newServer, imq });
410
- this.queueLength = this.imqs.length;
418
+ this.imqLength = this.imqs.length;
411
419
  return newServer;
412
420
  }
413
421
  eventEmitters() {
@@ -369,4 +369,11 @@ export interface IMessageQueue extends EventEmitter<EventMap> {
369
369
  * @returns {Promise<IMessageQueue>}
370
370
  */
371
371
  clear(): Promise<IMessageQueue>;
372
+ /**
373
+ * Retrieves the current count of messages in the queue.
374
+ * Supposed to be an async function.
375
+ *
376
+ * @returns {Promise<number>}
377
+ */
378
+ queueLength(): Promise<number>;
372
379
  }
@@ -194,11 +194,17 @@ export declare class RedisQueue extends EventEmitter<EventMap> implements IMessa
194
194
  */
195
195
  destroy(): Promise<void>;
196
196
  /**
197
- * Clears queue data in redis;
197
+ * Clears queue data in redis
198
198
  *
199
199
  * @returns {Promise<void>}
200
200
  */
201
201
  clear(): Promise<RedisQueue>;
202
+ /**
203
+ * Retrieves the current count of messages in the queue
204
+ *
205
+ * @returns {Promise<number>}
206
+ */
207
+ queueLength(): Promise<number>;
202
208
  /**
203
209
  * Returns true if publisher mode is enabled on this queue, false otherwise.
204
210
  *
package/src/RedisQueue.js CHANGED
@@ -356,7 +356,7 @@ class RedisQueue extends events_1.EventEmitter {
356
356
  await this.unsubscribe();
357
357
  }
358
358
  /**
359
- * Clears queue data in redis;
359
+ * Clears queue data in redis
360
360
  *
361
361
  * @returns {Promise<void>}
362
362
  */
@@ -378,6 +378,17 @@ class RedisQueue extends events_1.EventEmitter {
378
378
  }
379
379
  return this;
380
380
  }
381
+ /**
382
+ * Retrieves the current count of messages in the queue
383
+ *
384
+ * @returns {Promise<number>}
385
+ */
386
+ async queueLength() {
387
+ if (!this.writer) {
388
+ return 0;
389
+ }
390
+ return this.writer.llen(this.key);
391
+ }
381
392
  /**
382
393
  * Returns true if publisher mode is enabled on this queue, false otherwise.
383
394
  *
@@ -512,6 +523,8 @@ class RedisQueue extends events_1.EventEmitter {
512
523
  retryStrategy: this.retryStrategy(context),
513
524
  autoResubscribe: true,
514
525
  enableReadyCheck: true,
526
+ enableOfflineQueue: true,
527
+ autoResendUnfulfilledCommands: true,
515
528
  });
516
529
  context[channel] = (0, _1.makeRedisSafe)(redis);
517
530
  context[channel].__imq = true;
@@ -803,7 +816,7 @@ class RedisQueue extends events_1.EventEmitter {
803
816
  }
804
817
  const filter = new RegExp(this.options.prefix + ':' +
805
818
  (this.options.cleanupFilter || '*').replace(/\*/g, '.*'), 'i');
806
- const clients = await this.writer.client('LIST');
819
+ const clients = await this.writer.client('LIST') || '';
807
820
  const connectedKeys = (clients.match(RX_CLIENT_NAME) || [])
808
821
  .filter((name) => RX_CLIENT_TEST.test(name) && filter.test(name))
809
822
  .map((name) => name
@@ -1080,6 +1093,12 @@ __decorate([
1080
1093
  __metadata("design:paramtypes", []),
1081
1094
  __metadata("design:returntype", Promise)
1082
1095
  ], RedisQueue.prototype, "clear", null);
1096
+ __decorate([
1097
+ (0, _1.profile)(),
1098
+ __metadata("design:type", Function),
1099
+ __metadata("design:paramtypes", []),
1100
+ __metadata("design:returntype", Promise)
1101
+ ], RedisQueue.prototype, "queueLength", null);
1083
1102
  __decorate([
1084
1103
  (0, _1.profile)(),
1085
1104
  __metadata("design:type", Function),
package/debug.d.ts DELETED
@@ -1 +0,0 @@
1
- export {};
package/debug_getter.d.ts DELETED
@@ -1,9 +0,0 @@
1
- declare class DebugGetter {
2
- name: string;
3
- static propertiesMap: Record<string, string>;
4
- private get property();
5
- private set property(value);
6
- constructor(name: string);
7
- addProperty(value: string): void;
8
- removeProperty(): void;
9
- }
@@ -1 +0,0 @@
1
- export {};