mirror of
https://github.com/MindWorkAI/AI-Studio.git
synced 2025-04-28 07:59:47 +00:00
Implement semaphore for plugin loading to prevent concurrent initialization
This commit is contained in:
parent
5fe3e1cb34
commit
9cf4f943fb
@ -13,6 +13,7 @@ public static partial class PluginFactory
|
|||||||
private static readonly SettingsManager SETTINGS_MANAGER = Program.SERVICE_PROVIDER.GetRequiredService<SettingsManager>();
|
private static readonly SettingsManager SETTINGS_MANAGER = Program.SERVICE_PROVIDER.GetRequiredService<SettingsManager>();
|
||||||
private static readonly List<IAvailablePlugin> AVAILABLE_PLUGINS = [];
|
private static readonly List<IAvailablePlugin> AVAILABLE_PLUGINS = [];
|
||||||
private static readonly List<PluginBase> RUNNING_PLUGINS = [];
|
private static readonly List<PluginBase> RUNNING_PLUGINS = [];
|
||||||
|
private static readonly SemaphoreSlim PLUGIN_LOAD_SEMAPHORE = new(1, 1);
|
||||||
|
|
||||||
private static bool IS_INITIALIZED;
|
private static bool IS_INITIALIZED;
|
||||||
private static string DATA_DIR = string.Empty;
|
private static string DATA_DIR = string.Empty;
|
||||||
@ -73,6 +74,11 @@ public static partial class PluginFactory
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!await PLUGIN_LOAD_SEMAPHORE.WaitAsync(0, cancellationToken))
|
||||||
|
return;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
LOG.LogInformation("Start loading plugins.");
|
LOG.LogInformation("Start loading plugins.");
|
||||||
if (!Directory.Exists(PLUGINS_ROOT))
|
if (!Directory.Exists(PLUGINS_ROOT))
|
||||||
{
|
{
|
||||||
@ -127,6 +133,12 @@ public static partial class PluginFactory
|
|||||||
// Start or restart all plugins:
|
// Start or restart all plugins:
|
||||||
await RestartAllPlugins(cancellationToken);
|
await RestartAllPlugins(cancellationToken);
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
PLUGIN_LOAD_SEMAPHORE.Release();
|
||||||
|
LOG.LogInformation("Finished loading plugins.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static async Task<PluginBase> Load(string pluginPath, string code, CancellationToken cancellationToken = default)
|
private static async Task<PluginBase> Load(string pluginPath, string code, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user