mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Plugins - Added retry system when auto-enabling features
This commit is contained in:
1 parent
66b1620441
commit
9179010e12
2 files changed
+39
-7
No files matched your search
@@ -5,6 +5,7 @@ using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Artemis.Core.DeviceProviders;
|
||||
using Artemis.Core.Ninject;
|
||||
using Artemis.Storage.Entities.General;
|
||||
@@ -90,7 +91,7 @@ namespace Artemis.Core.Services
|
||||
using StreamReader reader = new(metaDataFileEntry.Open());
|
||||
PluginInfo builtInPluginInfo = CoreJson.DeserializeObject<PluginInfo>(reader.ReadToEnd())!;
|
||||
string preferred = builtInPluginInfo.PreferredPluginDirectory;
|
||||
|
||||
|
||||
// Find the matching plugin in the plugin folder
|
||||
DirectoryInfo? match = pluginDirectory.EnumerateDirectories().FirstOrDefault(d => d.Name == preferred);
|
||||
if (match == null)
|
||||
@@ -610,13 +611,38 @@ namespace Artemis.Core.Services
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.Warning(
|
||||
new ArtemisPluginException(pluginFeature.Plugin, $"Exception during SetEnabled(true) on {pluginFeature}", e),
|
||||
"Failed to enable plugin"
|
||||
);
|
||||
if (isAutoEnable)
|
||||
{
|
||||
// Schedule a retry based on the amount of attempts
|
||||
if (pluginFeature.AutoEnableAttempts < 4)
|
||||
{
|
||||
TimeSpan retryDelay = TimeSpan.FromSeconds(pluginFeature.AutoEnableAttempts * 10);
|
||||
_logger.Warning(
|
||||
e,
|
||||
"Plugin feature '{feature} - {plugin}' failed to enable during attempt ({attempt}/3), scheduling a retry in {retryDelay}.",
|
||||
pluginFeature,
|
||||
pluginFeature.Plugin,
|
||||
pluginFeature.AutoEnableAttempts,
|
||||
retryDelay
|
||||
);
|
||||
|
||||
if (!isAutoEnable)
|
||||
Task.Run(async () =>
|
||||
{
|
||||
await Task.Delay(retryDelay);
|
||||
if (!pluginFeature.IsEnabled)
|
||||
EnablePluginFeature(pluginFeature, saveState, true);
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Warning(e, "Plugin feature '{feature} - {plugin}' failed to enable after 3 attempts, giving up.", pluginFeature, pluginFeature.Plugin);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_logger.Warning(e, "Plugin feature '{feature} - {plugin}' failed to enable.", pluginFeature, pluginFeature.Plugin);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user