UNPKG

redis-smq

Version:

A simple high-performance Redis message queue for Node.js.

57 lines 1.94 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Worker = void 0; const redis_smq_common_1 = require("redis-smq-common"); const redis_client_js_1 = require("../../../common/redis-client/redis-client.js"); const index_js_1 = require("../../../config/index.js"); class Worker extends redis_smq_common_1.Runnable { constructor({ config, queueParsedParams, }) { super(); this.onTick = () => { if (this.isRunning()) { this.work((err) => { if (err) this.handleError(err); else this.timer.setTimeout(this.onTick, 1000); }); } }; this.handleError = (err) => { if (this.isRunning()) { throw err; } }; this.config = config; index_js_1.Configuration.getSetConfig(config); this.queueParsedParams = queueParsedParams; this.logger = redis_smq_common_1.logger.getLogger(config.logger, `worker:${this.constructor.name.toLowerCase()}:${this.id}`); this.redisClient = new redis_client_js_1.RedisClient(); this.redisClient.on('error', (err) => this.handleError(err)); this.timer = new redis_smq_common_1.Timer(); this.timer.on('error', (err) => this.handleError(err)); } getLogger() { return this.logger; } goingUp() { return super.goingUp().concat([ this.redisClient.init, (cb) => { this.timer.setTimeout(this.onTick, 1000); cb(); }, ]); } goingDown() { return [ (cb) => { this.timer.reset(); cb(); }, this.redisClient.shutdown, ].concat(super.goingDown()); } } exports.Worker = Worker; //# sourceMappingURL=worker.js.map