From d3ea85d5ac7010e34dff40ef923f4c66365c485b Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Wed, 12 May 2021 19:32:01 +0200 Subject: [PATCH] Add stopping instance status Notify when an instance is in the process of stopping with a separate status for it. This makes handling shutdown gracefully a bit simpler in plugin code. --- packages/lib/link/messages.js | 7 ++++--- packages/lib/plugin.js | 1 + packages/slave/slave.js | 3 ++- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/packages/lib/link/messages.js b/packages/lib/link/messages.js index 1bbf7bef..e4aedcb6 100644 --- a/packages/lib/link/messages.js +++ b/packages/lib/link/messages.js @@ -368,7 +368,8 @@ messages.listInstances = new Request({ "id": { type: "integer" }, "assigned_slave": { type: ["null", "integer"] }, "status": { enum: [ - "unknown", "unassigned", "stopped", "starting", "running", "creating_save", "exporting_data", + "unknown", "unassigned", "stopped", "starting", "running", "stopping", + "creating_save", "exporting_data", ]}, }, }, @@ -747,7 +748,7 @@ messages.updateInstances = new Request({ properties: { "serialized_config": { type: "object" }, "status": { enum: [ - "stopped", "starting", "running", "creating_save", "exporting_data", + "stopped", "starting", "running", "stopping", "creating_save", "exporting_data", ]}, }, }, @@ -979,7 +980,7 @@ messages.instanceStatusChanged = new Event({ eventProperties: { "instance_id": { type: "integer" }, "status": { enum: [ - "stopped", "starting", "running", "creating_save", "exporting_data", + "stopped", "starting", "running", "stopping", "creating_save", "exporting_data", ]}, }, }); diff --git a/packages/lib/plugin.js b/packages/lib/plugin.js index 3f76abd0..3d1e96fe 100644 --- a/packages/lib/plugin.js +++ b/packages/lib/plugin.js @@ -260,6 +260,7 @@ class BaseMasterPlugin { * slave. * - `starting`: Instance is in the process of starting up. * - `running`: Instance startup completed and is now running. + * - `stopping`: Instance is in the processing stopping. * - `creating_save`: Instance is in the process of creating a save. * - `exporting_data`: Instance is in the process of exporting item * icons and locale data. diff --git a/packages/slave/slave.js b/packages/slave/slave.js index a1217226..2ee280b2 100755 --- a/packages/slave/slave.js +++ b/packages/slave/slave.js @@ -224,7 +224,7 @@ class Instance extends libLink.Link { /** * Current state of the instance * - * One of stopped, starting, running, creating_save and exporting_data + * One of stopped, starting, running, stopping, creating_save and exporting_data * * @returns {string} instance status. */ @@ -623,6 +623,7 @@ class Instance extends libLink.Link { */ async stop() { this._running = false; + this.notifyStatus("stopping"); // XXX this needs more thought to it if (this.server._state === "running") {