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

93.33% Statements 14/15
66.66% Branches 4/6
100% Functions 7/7
100% Lines 14/14

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  57x 57x 57x 57x     57x 35x 35x     35x     35x     35x         35x   35x     35x                             57x  
import { ICallback, TQueueParams } from 'redis-smq/dist/types';
import { Consumer } from 'redis-smq/dist/src/lib/consumer/consumer';
import { Worker } from 'redis-smq/dist/src/common/worker/worker';
import { each, waterfall } from 'redis-smq/dist/src/util/async';
import { Queue } from 'redis-smq/dist/src/lib/queue-manager/queue';
import { IMonitorWorkerParameters } from '../../types';
 
export class WebsocketOnlineStreamWorker extends Worker<IMonitorWorkerParameters> {
  work = (cb: ICallback<void>): void => {
    waterfall(
      [
        (cb: ICallback<TQueueParams[]>) => {
          Queue.list(this.redisClient, cb);
        },
        (queues: TQueueParams[], done: ICallback<void>) => {
          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;