mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-23 08:23:12 +09:00
Merge pull request #675 from clusterio/fix-instance-update
Fix instance update
This commit is contained in:
3 files changed
+17
-4
No files matched your search
@@ -924,9 +924,7 @@ export default class Controller {
|
|||||||
addInstanceHooks(instance: InstanceInfo) {
|
addInstanceHooks(instance: InstanceInfo) {
|
||||||
instance.config.on("fieldChanged", (field: string, curr: any, prev: any) => {
|
instance.config.on("fieldChanged", (field: string, curr: any, prev: any) => {
|
||||||
instance.updatedAtMs = Date.now();
|
instance.updatedAtMs = Date.now();
|
||||||
if (field === "instance.name") {
|
this.instances.set(instance); // Trigger update logic
|
||||||
this.instances.set(instance); // Trigger updated logic
|
|
||||||
}
|
|
||||||
|
|
||||||
lib.invokeHook(this.plugins, "onInstanceConfigFieldChanged", instance, field, curr, prev);
|
lib.invokeHook(this.plugins, "onInstanceConfigFieldChanged", instance, field, curr, prev);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import fs from "fs-extra";
|
|||||||
|
|
||||||
import { safeOutputFile } from "./file_ops";
|
import { safeOutputFile } from "./file_ops";
|
||||||
import { SubscribableValue } from "./subscriptions";
|
import { SubscribableValue } from "./subscriptions";
|
||||||
|
import { logger } from "./logging";
|
||||||
import { EventEmitter } from "stream";
|
import { EventEmitter } from "stream";
|
||||||
import { ControllerConfig } from "./config";
|
import { ControllerConfig } from "./config";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
@@ -60,6 +61,7 @@ export class JsonDatastoreProvider<
|
|||||||
|
|
||||||
// Save the data to the json file
|
// Save the data to the json file
|
||||||
async save(data: Map<K, V>) {
|
async save(data: Map<K, V>) {
|
||||||
|
logger.verbose(`Saving ${this.filePath}`);
|
||||||
await safeOutputFile(this.filePath, JSON.stringify(Object.fromEntries(data), null, "\t"));
|
await safeOutputFile(this.filePath, JSON.stringify(Object.fromEntries(data), null, "\t"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -68,6 +70,7 @@ export class JsonDatastoreProvider<
|
|||||||
// Read the raw json from the file
|
// Read the raw json from the file
|
||||||
let rawJson;
|
let rawJson;
|
||||||
try {
|
try {
|
||||||
|
logger.verbose(`Loading ${this.filePath}`);
|
||||||
rawJson = JSON.parse(await fs.readFile(this.filePath, { encoding: "utf8" }));
|
rawJson = JSON.parse(await fs.readFile(this.filePath, { encoding: "utf8" }));
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
if (err.code !== "ENOENT") {
|
if (err.code !== "ENOENT") {
|
||||||
@@ -101,6 +104,7 @@ export class JsonIdDatastoreProvider<
|
|||||||
|
|
||||||
// Save the data to the json file
|
// Save the data to the json file
|
||||||
async save(data: Map<K, V>) {
|
async save(data: Map<K, V>) {
|
||||||
|
logger.verbose(`Saving ${this.filePath}`);
|
||||||
await safeOutputFile(this.filePath, JSON.stringify([...data.values()], null, "\t"));
|
await safeOutputFile(this.filePath, JSON.stringify([...data.values()], null, "\t"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,6 +113,7 @@ export class JsonIdDatastoreProvider<
|
|||||||
// Read the raw json from the file
|
// Read the raw json from the file
|
||||||
let rawJson;
|
let rawJson;
|
||||||
try {
|
try {
|
||||||
|
logger.verbose(`Loading ${this.filePath}`);
|
||||||
rawJson = JSON.parse(await fs.readFile(this.filePath, { encoding: "utf8" }));
|
rawJson = JSON.parse(await fs.readFile(this.filePath, { encoding: "utf8" }));
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
if (err.code !== "ENOENT") {
|
if (err.code !== "ENOENT") {
|
||||||
|
|||||||
@@ -17,7 +17,9 @@ class MockInstanceConfig extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
set(field, value) {
|
set(field, value) {
|
||||||
return this._data.set(field, value);
|
const prev = this.get(field);
|
||||||
|
this._data.set(field, value);
|
||||||
|
this.emit("fieldChanged", field, value, prev);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,5 +181,13 @@ describe("controller/src/Controller", function() {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe(".instances", function() {
|
||||||
|
it("should set the dirty flag if the config is updated", function() {
|
||||||
|
controller.instances.dirty = false;
|
||||||
|
mockInstanceConfig.set("instance.assigned_host", null);
|
||||||
|
assert(controller.instances.dirty === true, "dirty flag was not set");
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user