UNPKG

log-vault

Version:

A generator of Winston logger instance with pre-defined configurable transports and formats and extra functionality.

38 lines (37 loc) 1.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Notificator = void 0; const bullmq_1 = require("bullmq"); const defaults_1 = require("../defaults"); const matchPattern_1 = require("./util/matchPattern"); const util_1 = require("../util"); class Notificator { constructor(opts = {}) { this.channels = []; const { queueName = (0, util_1.projectDirName)(), workerOpts } = opts; this.worker = new bullmq_1.Worker(queueName, async (job) => { const matchedChannels = (0, matchPattern_1.matchPattern)(job.data, this.channels); return await Promise.all(matchedChannels.map((c) => c.addToQueue(job.data))); }, { connection: defaults_1.defaultRedisConnection, autorun: true, ...workerOpts }); this.worker.on("error", (err) => { console.error(err); }); } run() { this.worker.run(); return this; } async stop() { await this.worker.close(); return this; } add(channel) { this.channels.push(channel); return this; } } exports.Notificator = Notificator;