forked from mirror/MCSM-Daemon
feat: global instance filter
This commit is contained in:
parent
a5608a45a3
commit
349ca381e3
@ -88,7 +88,7 @@ initDependent();
|
|||||||
// Initialize application instance system
|
// Initialize application instance system
|
||||||
try {
|
try {
|
||||||
InstanceSubsystem.loadInstances();
|
InstanceSubsystem.loadInstances();
|
||||||
logger.info($t("app.instanceLoad", { n: InstanceSubsystem.instances.size }));
|
logger.info($t("app.instanceLoad", { n: InstanceSubsystem.getInstances().length }));
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error($t("app.instanceLoadError"), err);
|
logger.error($t("app.instanceLoadError"), err);
|
||||||
process.exit(-1);
|
process.exit(-1);
|
||||||
|
@ -54,9 +54,11 @@ routerApp.on("instance/select", (ctx, data) => {
|
|||||||
// keyword condition query
|
// keyword condition query
|
||||||
const queryWrapper = InstanceSubsystem.getQueryMapWrapper();
|
const queryWrapper = InstanceSubsystem.getQueryMapWrapper();
|
||||||
let result = queryWrapper.select<Instance>((v) => {
|
let result = queryWrapper.select<Instance>((v) => {
|
||||||
|
if (InstanceSubsystem.isGlobalInstance(v)) return false;
|
||||||
if (!v.config.nickname.toLowerCase().includes(condition.instanceName.toLowerCase())) return false;
|
if (!v.config.nickname.toLowerCase().includes(condition.instanceName.toLowerCase())) return false;
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
result = result.sort((a, b) => (a.config.nickname > b.config.nickname ? 1 : -1));
|
||||||
// paging function
|
// paging function
|
||||||
const pageResult = queryWrapper.page<Instance>(result, page, pageSize);
|
const pageResult = queryWrapper.page<Instance>(result, page, pageSize);
|
||||||
// filter unwanted data
|
// filter unwanted data
|
||||||
@ -85,7 +87,7 @@ routerApp.on("instance/select", (ctx, data) => {
|
|||||||
// Get an overview of this daemon instance
|
// Get an overview of this daemon instance
|
||||||
routerApp.on("instance/overview", (ctx) => {
|
routerApp.on("instance/overview", (ctx) => {
|
||||||
const overview: IInstanceDetail[] = [];
|
const overview: IInstanceDetail[] = [];
|
||||||
InstanceSubsystem.instances.forEach((instance) => {
|
InstanceSubsystem.getInstances().forEach((instance) => {
|
||||||
overview.push({
|
overview.push({
|
||||||
instanceUuid: instance.instanceUuid,
|
instanceUuid: instance.instanceUuid,
|
||||||
started: instance.startCount,
|
started: instance.startCount,
|
||||||
@ -102,7 +104,7 @@ routerApp.on("instance/overview", (ctx) => {
|
|||||||
routerApp.on("instance/section", (ctx, data) => {
|
routerApp.on("instance/section", (ctx, data) => {
|
||||||
const instanceUuids = data.instanceUuids as string[];
|
const instanceUuids = data.instanceUuids as string[];
|
||||||
const overview: IInstanceDetail[] = [];
|
const overview: IInstanceDetail[] = [];
|
||||||
InstanceSubsystem.instances.forEach((instance) => {
|
InstanceSubsystem.getInstances().forEach((instance) => {
|
||||||
instanceUuids.forEach((targetUuid) => {
|
instanceUuids.forEach((targetUuid) => {
|
||||||
if (targetUuid === instance.instanceUuid) {
|
if (targetUuid === instance.instanceUuid) {
|
||||||
overview.push({
|
overview.push({
|
||||||
|
@ -18,7 +18,7 @@ routerApp.on("info/overview", async (ctx) => {
|
|||||||
const daemonVersion = getVersion();
|
const daemonVersion = getVersion();
|
||||||
let total = 0;
|
let total = 0;
|
||||||
let running = 0;
|
let running = 0;
|
||||||
InstanceSubsystem.instances.forEach((v) => {
|
InstanceSubsystem.getInstances().forEach((v) => {
|
||||||
total++;
|
total++;
|
||||||
if (v.status() == Instance.STATUS_RUNNING) running++;
|
if (v.status() == Instance.STATUS_RUNNING) running++;
|
||||||
});
|
});
|
||||||
|
@ -216,8 +216,7 @@ class InstanceSubsystem extends EventEmitter {
|
|||||||
logger.info(`Instance ${instance.config.nickname} (${instance.instanceUuid}) is running or busy, and is being forced to end.`);
|
logger.info(`Instance ${instance.config.nickname} (${instance.instanceUuid}) is running or busy, and is being forced to end.`);
|
||||||
promises.push(
|
promises.push(
|
||||||
instance.execCommand(new KillCommand()).then(() => {
|
instance.execCommand(new KillCommand()).then(() => {
|
||||||
if (instance.config.nickname !== InstanceSubsystem.GLOBAL_INSTANCE)
|
if (!this.isGlobalInstance(instance)) StorageSubsystem.store("InstanceConfig", instance.instanceUuid, instance.config);
|
||||||
StorageSubsystem.store("InstanceConfig", instance.instanceUuid, instance.config);
|
|
||||||
logger.info(`Instance ${instance.config.nickname} (${instance.instanceUuid}) saved successfully.`);
|
logger.info(`Instance ${instance.config.nickname} (${instance.instanceUuid}) saved successfully.`);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@ -225,6 +224,19 @@ class InstanceSubsystem extends EventEmitter {
|
|||||||
}
|
}
|
||||||
await Promise.all(promises);
|
await Promise.all(promises);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getInstances() {
|
||||||
|
let newArr = new Array<Instance>();
|
||||||
|
this.instances.forEach((instance) => {
|
||||||
|
if (!this.isGlobalInstance(instance)) newArr.push(instance);
|
||||||
|
});
|
||||||
|
newArr = newArr.sort((a, b) => (a.config.nickname > a.config.nickname ? 1 : -1));
|
||||||
|
return newArr;
|
||||||
|
}
|
||||||
|
|
||||||
|
isGlobalInstance(instance: Instance) {
|
||||||
|
return instance.instanceUuid === InstanceSubsystem.GLOBAL_INSTANCE_UUID || instance.config.nickname === InstanceSubsystem.GLOBAL_INSTANCE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default new InstanceSubsystem();
|
export default new InstanceSubsystem();
|
||||||
|
Loading…
Reference in New Issue
Block a user