UNPKG

redis-smq

Version:

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

42 lines 1.53 kB
import { async } from 'redis-smq-common'; import { parseConfig } from './parse-config.js'; import { InvalidConfigurationError } from '../errors/index.js'; import { Configuration } from './configuration.js'; export class ConfigManager { mergeConfig(current, updates) { return { ...current, ...updates, }; } reload(cb) { return async.withOptionalCallback(cb, (callback) => { Configuration.getInstance().reload((err, reply) => callback(err, reply?.data)); }); } updateConfig(updates, cb) { return async.withOptionalCallback(cb, (callback) => { try { const configuration = Configuration.getInstance(); const currentConfig = Configuration.getConfig(); const updatedConfig = this.mergeConfig(currentConfig, updates); const parsedConfig = parseConfig(updatedConfig); if (JSON.stringify(currentConfig) === JSON.stringify(parsedConfig)) { return callback(); } configuration.save(parsedConfig, callback); } catch (e) { const err = e instanceof Error ? e : new InvalidConfigurationError(); return callback(err); } }); } getConfigVersion() { return Configuration.getInstance().getConfig().version; } getConfig() { return Configuration.getConfig(); } } //# sourceMappingURL=config-manager.js.map