All files / redis-smq-monitor-app/tests/common queue-manager.ts

100% Statements 21/21
100% Branches 4/4
100% Functions 3/3
100% Lines 21/21

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  57x 57x 57x   57x   57x   57x 51x 39x   51x     57x 37x 37x 37x 37x 37x 37x               57x 57x 39x 39x 39x      
import { IConfig } from 'redis-smq/dist/types';
import { config } from './config';
import { promisifyAll } from 'bluebird';
import { QueueManager } from 'redis-smq';
 
const QueueManagerAsync = promisifyAll(QueueManager);
 
let queueManager: QueueManager | null = null;
 
export async function getQueueManager(cfg: IConfig = config) {
  if (!queueManager) {
    queueManager = await QueueManagerAsync.createInstanceAsync(cfg);
  }
  return queueManager;
}
 
export async function getQueueManagerAsync(cfg: IConfig = config) {
  const queueManager = await getQueueManager(cfg);
  const queue = promisifyAll(queueManager.queue);
  const namespace = promisifyAll(queueManager.namespace);
  const queueRateLimit = promisifyAll(queueManager.queueRateLimit);
  const queueMetrics = promisifyAll(queueManager.queueMetrics);
  return {
    queue,
    namespace,
    queueRateLimit,
    queueMetrics,
  };
}
 
export async function shutdownQueueManager() {
  if (queueManager) {
    const q = promisifyAll(queueManager);
    await q.quitAsync();
    queueManager = null;
  }
}