All files / redis-smq-monitor-app/src/workers websocket-online-stream.worker.ts

93.75% Statements 15/16
66.66% Branches 4/6
100% Functions 7/7
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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54  57x   57x   57x                 35x 35x 35x     35x 35x   35x   35x     35x         35x   35x     35x                             57x  
import { TQueueParams } from 'redis-smq/dist/types';
import { Consumer, QueueManager } from 'redis-smq';
import { ICallback } from 'redis-smq-common/dist/types';
import { async, RedisClient, Worker } from 'redis-smq-common';
 
export class WebsocketOnlineStreamWorker extends Worker {
  protected queueManager: QueueManager;
  protected redisClient: RedisClient;
 
  constructor(
    redisClient: RedisClient,
    queueManager: QueueManager,
    managed: boolean,
  ) {
    super(managed);
    this.queueManager = queueManager;
    this.redisClient = redisClient;
  }
 
  work = (cb: ICallback<void>): void => {
    async.waterfall(
      [
        (cb: ICallback<TQueueParams[]>) => this.queueManager.queue.list(cb),
        (queues: TQueueParams[], done: ICallback<void>) => {
          async.each(
            queues,
            (item, _, done) => {
              Consumer.getOnlineConsumers(
                this.redisClient,
                item,
                false,
                (err, reply) => {
                  Iif (err) done(err);
                  else {
                    this.redisClient.publish(
                      `streamOnlineQueueConsumers:${item.ns}:${item.name}`,
                      JSON.stringify(reply ?? {}),
                      () => done(),
                    );
                  }
                },
              );
            },
            done,
          );
        },
      ],
      cb,
    );
  };
}
 
export default WebsocketOnlineStreamWorker;