log-vault
Version:
A generator of Winston logger instance with pre-defined configurable transports and formats and extra functionality.
51 lines (50 loc) • 1.89 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.NotificationChannel = void 0;
const defaultJobOptions_1 = require("./../../defaults/defaultJobOptions");
const bullmq_1 = require("bullmq");
const node_crypto_1 = require("node:crypto");
const node_stream_1 = require("node:stream");
const defaults_1 = require("../../defaults");
class NotificationChannel extends node_stream_1.EventEmitter {
constructor(opts = {}) {
super();
this.processor = async (job) => {
this.emit("processed", job.data);
};
const { matchPatterns = [], inspectOptions = {} } = opts;
this.matchPatterns = matchPatterns;
this.inspectOptions = {
depth: 3,
maxArrayLength: 10,
maxStringLength: 1024,
...inspectOptions
};
}
process(opts) {
const { processor, workerOptions = {}, queueName, queueOptions = {}, jobOptions = {} } = opts;
this.queue = new bullmq_1.Queue(queueName, {
connection: defaults_1.defaultRedisConnection,
...queueOptions
});
this.jobOptions = {
...defaultJobOptions_1.defaultJobOptions,
...jobOptions
};
this.worker = new bullmq_1.Worker(queueName, processor, {
connection: defaults_1.defaultRedisConnection,
...workerOptions
});
return this;
}
async addToQueue(log) {
var _a;
await ((_a = this.queue) === null || _a === void 0 ? void 0 : _a.add((0, node_crypto_1.randomUUID)(), log, this.jobOptions));
}
async stop() {
var _a, _b;
await ((_a = this.queue) === null || _a === void 0 ? void 0 : _a.obliterate());
await ((_b = this.worker) === null || _b === void 0 ? void 0 : _b.close());
}
}
exports.NotificationChannel = NotificationChannel;