mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-23 16:23:12 +09:00
Merge pull request #1232 from bbassie/feature/wait-for-plugin
Add waitForPlugin and load plugins concurrently
This commit is contained in:
20 files changed
+800
-411
No files matched your search
+14
-19
@@ -490,7 +490,7 @@ export default class Host extends lib.Link {
|
||||
}
|
||||
|
||||
async loadPlugins() {
|
||||
const context = { logger, host: this };
|
||||
const toLoad: lib.PluginNodeEnvInfo[] = [];
|
||||
for (let pluginInfo of this.pluginInfos) {
|
||||
if (
|
||||
!pluginInfo.hostEntrypoint && !pluginInfo.instanceEntrypoint
|
||||
@@ -504,25 +504,20 @@ export default class Host extends lib.Link {
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
await lib.loadPlugin(
|
||||
pluginInfo,
|
||||
"host",
|
||||
context,
|
||||
"HostPlugin",
|
||||
BaseHostPlugin,
|
||||
);
|
||||
toLoad.push(pluginInfo);
|
||||
}
|
||||
|
||||
this.loadedPlugins.add(pluginInfo);
|
||||
|
||||
} catch (err: any) {
|
||||
if (err.code === "InstallationError") {
|
||||
throw err;
|
||||
}
|
||||
throw new lib.PluginError(pluginInfo.name, err);
|
||||
}
|
||||
|
||||
logger.info(`Loaded plugin ${pluginInfo.name}`);
|
||||
const { loaded } = await lib.PluginLoader.load({
|
||||
type: "host",
|
||||
context: { host: this },
|
||||
logger,
|
||||
installed: this.pluginInfos,
|
||||
load: toLoad,
|
||||
exportName: "HostPlugin",
|
||||
baseClass: BaseHostPlugin,
|
||||
});
|
||||
for (const pluginInfo of loaded.keys()) {
|
||||
this.loadedPlugins.add(pluginInfo);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -804,8 +804,7 @@ end`.replace(/\r?\n/g, " ");
|
||||
* Must be called once the instance is connected to the host.
|
||||
*/
|
||||
async loadPlugins(pluginInfos: lib.PluginNodeEnvInfo[]) {
|
||||
// load plugins
|
||||
const plugins: Record<string, string> = {};
|
||||
const toLoad: lib.PluginNodeEnvInfo[] = [];
|
||||
for (let pluginInfo of pluginInfos) {
|
||||
if (
|
||||
!pluginInfo.instanceEntrypoint
|
||||
@@ -820,26 +819,31 @@ end`.replace(/\r?\n/g, " ");
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
let pluginLoadStartedMs = Date.now();
|
||||
await lib.loadPlugin(
|
||||
pluginInfo,
|
||||
"instance",
|
||||
{ logger: this.logger, host: this._host, instance: this },
|
||||
"InstancePlugin",
|
||||
BaseInstancePlugin,
|
||||
);
|
||||
|
||||
this.loadedPlugins.add(pluginInfo);
|
||||
plugins[pluginInfo.name] = pluginInfo.version;
|
||||
this.logger.info(`Loaded plugin ${pluginInfo.name} in ${Date.now() - pluginLoadStartedMs}ms`);
|
||||
} catch (err) {
|
||||
this.notifyExit();
|
||||
await this.sendSaveListUpdate();
|
||||
throw err;
|
||||
}
|
||||
toLoad.push(pluginInfo);
|
||||
}
|
||||
|
||||
let loaded;
|
||||
try {
|
||||
({ loaded } = await lib.PluginLoader.load({
|
||||
type: "instance",
|
||||
context: { host: this._host, instance: this },
|
||||
logger: this.logger,
|
||||
installed: pluginInfos,
|
||||
load: toLoad,
|
||||
exportName: "InstancePlugin",
|
||||
baseClass: BaseInstancePlugin,
|
||||
}));
|
||||
} catch (err) {
|
||||
this.notifyExit();
|
||||
await this.sendSaveListUpdate();
|
||||
throw err;
|
||||
}
|
||||
|
||||
const plugins: Record<string, string> = {};
|
||||
for (const pluginInfo of loaded.keys()) {
|
||||
this.loadedPlugins.add(pluginInfo);
|
||||
plugins[pluginInfo.name] = pluginInfo.version;
|
||||
}
|
||||
this.send(new lib.InstanceInitialisedEvent(plugins));
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user