UNPKG

redis-smq

Version:

A high-performance, reliable, and scalable message queue for Node.js.

43 lines 1.89 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ConfigManager = void 0; const redis_smq_common_1 = require("redis-smq-common"); const parse_config_js_1 = require("./parse-config.js"); const index_js_1 = require("../errors/index.js"); const configuration_js_1 = require("./configuration.js"); class ConfigManager { mergeConfig(current, updates) { return Object.assign(Object.assign({}, current), updates); } reload(cb) { return redis_smq_common_1.async.withOptionalCallback(cb, (callback) => { configuration_js_1.Configuration.getInstance().reload((err, reply) => callback(err, reply === null || reply === void 0 ? void 0 : reply.data)); }); } updateConfig(updates, cb) { return redis_smq_common_1.async.withOptionalCallback(cb, (callback) => { try { const configuration = configuration_js_1.Configuration.getInstance(); const currentConfig = configuration_js_1.Configuration.getConfig(); const updatedConfig = this.mergeConfig(currentConfig, updates); const parsedConfig = (0, parse_config_js_1.parseConfig)(updatedConfig); if (JSON.stringify(currentConfig) === JSON.stringify(parsedConfig)) { return callback(); } configuration.save(parsedConfig, callback); } catch (e) { const err = e instanceof Error ? e : new index_js_1.InvalidConfigurationError(); return callback(err); } }); } getConfigVersion() { return configuration_js_1.Configuration.getInstance().getConfig().version; } getConfig() { return configuration_js_1.Configuration.getConfig(); } } exports.ConfigManager = ConfigManager; //# sourceMappingURL=config-manager.js.map