mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Plugins - Added retry system when auto-enabling features
This commit is contained in:
parent
66b1620441
commit
9179010e12
@ -12,7 +12,7 @@ namespace Artemis.Core
|
|||||||
{
|
{
|
||||||
private bool _isEnabled;
|
private bool _isEnabled;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the plugin feature info related to this feature
|
/// Gets the plugin feature info related to this feature
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -37,6 +37,8 @@ namespace Artemis.Core
|
|||||||
internal set => SetAndNotify(ref _isEnabled, value);
|
internal set => SetAndNotify(ref _isEnabled, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal int AutoEnableAttempts { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the identifier of this plugin feature
|
/// Gets the identifier of this plugin feature
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -137,6 +139,9 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
if (isAutoEnable)
|
||||||
|
AutoEnableAttempts++;
|
||||||
|
|
||||||
if (isAutoEnable && GetLockFileCreated())
|
if (isAutoEnable && GetLockFileCreated())
|
||||||
{
|
{
|
||||||
// Don't wrap existing lock exceptions, simply rethrow them
|
// Don't wrap existing lock exceptions, simply rethrow them
|
||||||
@ -157,6 +162,7 @@ namespace Artemis.Core
|
|||||||
throw new ArtemisPluginException(Plugin, "Plugin load timeout");
|
throw new ArtemisPluginException(Plugin, "Plugin load timeout");
|
||||||
|
|
||||||
Info.LoadException = null;
|
Info.LoadException = null;
|
||||||
|
AutoEnableAttempts = 0;
|
||||||
OnEnabled();
|
OnEnabled();
|
||||||
}
|
}
|
||||||
// If enable failed, put it back in a disabled state
|
// If enable failed, put it back in a disabled state
|
||||||
|
|||||||
@ -5,6 +5,7 @@ using System.IO;
|
|||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Artemis.Core.DeviceProviders;
|
using Artemis.Core.DeviceProviders;
|
||||||
using Artemis.Core.Ninject;
|
using Artemis.Core.Ninject;
|
||||||
using Artemis.Storage.Entities.General;
|
using Artemis.Storage.Entities.General;
|
||||||
@ -90,7 +91,7 @@ namespace Artemis.Core.Services
|
|||||||
using StreamReader reader = new(metaDataFileEntry.Open());
|
using StreamReader reader = new(metaDataFileEntry.Open());
|
||||||
PluginInfo builtInPluginInfo = CoreJson.DeserializeObject<PluginInfo>(reader.ReadToEnd())!;
|
PluginInfo builtInPluginInfo = CoreJson.DeserializeObject<PluginInfo>(reader.ReadToEnd())!;
|
||||||
string preferred = builtInPluginInfo.PreferredPluginDirectory;
|
string preferred = builtInPluginInfo.PreferredPluginDirectory;
|
||||||
|
|
||||||
// Find the matching plugin in the plugin folder
|
// Find the matching plugin in the plugin folder
|
||||||
DirectoryInfo? match = pluginDirectory.EnumerateDirectories().FirstOrDefault(d => d.Name == preferred);
|
DirectoryInfo? match = pluginDirectory.EnumerateDirectories().FirstOrDefault(d => d.Name == preferred);
|
||||||
if (match == null)
|
if (match == null)
|
||||||
@ -610,13 +611,38 @@ namespace Artemis.Core.Services
|
|||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
_logger.Warning(
|
if (isAutoEnable)
|
||||||
new ArtemisPluginException(pluginFeature.Plugin, $"Exception during SetEnabled(true) on {pluginFeature}", e),
|
{
|
||||||
"Failed to enable plugin"
|
// 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;
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user