All files / redis-smq-monitor-app/src/plugins/message-rate/producer producer-message-rate.ts

100% Statements 15/15
100% Branches 1/1
100% Functions 3/3
100% Lines 15/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33  57x     57x 31x 31x     34x 34x 31x   34x 34x       157x 157x 157x     157x 155x   157x            
import { TQueueParams } from 'redis-smq/dist/types';
import { MessageRate } from '../common/message-rate';
import { IProducerMessageRateFields } from '../../../../types';
 
export class ProducerMessageRate extends MessageRate<IProducerMessageRateFields> {
  protected publishedRate = 0;
  protected queuePublishedRate: Record<string, number> = {};
 
  incrementPublished(queue: TQueueParams): void {
    const key = `${queue.ns}:${queue.name}`;
    if (!this.queuePublishedRate[key]) {
      this.queuePublishedRate[key] = 0;
    }
    this.queuePublishedRate[key] += 1;
    this.publishedRate += 1;
  }
 
  getRateFields(): IProducerMessageRateFields {
    const publishedRate = this.publishedRate;
    this.publishedRate = 0;
    const queuePublishedRate = {
      ...this.queuePublishedRate,
    };
    for (const key in this.queuePublishedRate) {
      this.queuePublishedRate[key] = 0;
    }
    return {
      publishedRate,
      queuePublishedRate,
    };
  }
}