Add instance update subscription

Provide the control link with the ability to subscribe to updates when
instance status and properties changes.  This allows the web interface
to respond in real time to instance starts and stops that are triggered
from somewhere else.
This commit is contained in:
Hornwitser committed 2021-05-21 17:27:01 +02:00
1 parent bda103d7a0
commit 6ffcb8c451
11 files changed
+219 -29

No files matched your search

+16
View File
@@ -325,6 +325,22 @@ describe("Integration of Clusterio", function() {
});
});
describe("instanceUpdateEventHandler()", function() {
it("should have triggered for the previous instance status updates", function() {
let statusesToCheck = new Set(
["unassigned", "stopped", "creating_save", "exporting_data", "starting", "running", "stopping"]
);
let statusesNotSeen = new Set(statusesToCheck);
for (let update of getControl().instanceUpdates) {
assert(statusesToCheck.has(update.status), `Missing check for status ${update.status}`);
statusesNotSeen.delete(update.status);
}
assert(statusesNotSeen.size === 0, `Did not see the statuses ${[...statusesNotSeen]}`);
});
});
describe("permission list", function() {
it("runs", async function() {
await execCtl("permission list");
+11
View File
@@ -25,6 +25,13 @@ class TestControl extends libLink.Link {
constructor(connector) {
super("control", "master", connector);
libLink.attachAllMessages(this);
this.instanceUpdates = [];
this.connector.on("connect", () => {
libLink.messages.setInstanceSubscriptions.send(
this, { all: true, instance_ids: [] }
).catch(err => logger.error(`Error setting instance subscriptions:\n${err.stack}`));
});
}
async prepareDisconnectRequestHandler(message, request) {
@@ -34,6 +41,10 @@ class TestControl extends libLink.Link {
async debugWsMessageEventHandler() { }
async instanceUpdateEventHandler(message) {
this.instanceUpdates.push(message.data);
}
async logMessageEventHandler() { }
}