diff --git a/packages/lib/plugin.js b/packages/lib/plugin.js index 796b9b6c..9d4e7e6f 100644 --- a/packages/lib/plugin.js +++ b/packages/lib/plugin.js @@ -355,6 +355,19 @@ class BaseMasterPlugin { */ async onInstanceStatusChanged(instance, prev) { } + /** + * Called when the value of a master config field changed. + * + * Invoked after the value of the config field given by `field` has + * changed on the master. + * + * @param {module:lib/config.ConfigGroup} group - + * The group who's field got changed on. + * @param {string} field - Name of the field that changed. + * @param {*} prev - The previous value of the field. + */ + async onMasterConfigFieldChanged(group, field, prev) { } + /** * Called when the value of an instance config field changed. * diff --git a/packages/master/src/Master.js b/packages/master/src/Master.js index 28809002..3d83e849 100644 --- a/packages/master/src/Master.js +++ b/packages/master/src/Master.js @@ -162,6 +162,9 @@ class Master { this.userManager = new UserManager(this.config); await this.userManager.load(path.join(databaseDirectory, "users.json")); + this.config.on("fieldChanged", (group, field, prev) => { + libPlugin.invokeHook(this.plugins, "onMasterConfigFieldChanged", group, field, prev); + }); for (let instance of this.instances.values()) { this.addInstanceHooks(instance); } diff --git a/test/lib/plugin.js b/test/lib/plugin.js index 55159f4f..017385ae 100644 --- a/test/lib/plugin.js +++ b/test/lib/plugin.js @@ -62,6 +62,8 @@ describe("lib/plugin", function() { }); it("should define defaults for hooks", async function() { await masterPlugin.onInstanceStatusChanged({}, "running", "initialized"); + await masterPlugin.onMasterConfigFieldChanged({}, "foo", null); + await masterPlugin.onInstanceConfigFieldChanged({}, {}, "foo", null); await masterPlugin.onMetrics(); await masterPlugin.onShutdown(); masterPlugin.onSlaveConnectionEvent({}, "connect");