Add onMasterConfigFieldChanged hook

Add hook for master plugin code to react to the master config changing.
This commit is contained in:
Hornwitser committed 2022-02-10 10:29:47 +01:00
1 parent a979c0cfac
commit 68b8ac6b8c
3 files changed
+18

No files matched your search

+13
View File
@@ -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.
*
+3
View File
@@ -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);
}
+2
View File
@@ -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");