mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-01-02 10:43:31 +00:00
Core - Log exceptions in timed updates, this closes #508
This commit is contained in:
parent
467473f06c
commit
ea6c081f22
@ -2,6 +2,9 @@
|
||||
using System.Threading.Tasks;
|
||||
using System.Timers;
|
||||
using Artemis.Core.Modules;
|
||||
using Artemis.Core.Services;
|
||||
using Ninject;
|
||||
using Serilog;
|
||||
|
||||
namespace Artemis.Core
|
||||
{
|
||||
@ -14,9 +17,12 @@ namespace Artemis.Core
|
||||
private Timer? _timer;
|
||||
private bool _disposed;
|
||||
private readonly object _lock = new();
|
||||
private ILogger _logger;
|
||||
|
||||
internal TimedUpdateRegistration(PluginFeature feature, TimeSpan interval, Action<double> action)
|
||||
{
|
||||
_logger = CoreService.Kernel.Get<ILogger>();
|
||||
|
||||
Feature = feature;
|
||||
Interval = interval;
|
||||
Action = action;
|
||||
@ -119,12 +125,19 @@ namespace Artemis.Core
|
||||
if (Feature is Module module && !module.IsUpdateAllowed)
|
||||
return;
|
||||
|
||||
if (Action != null)
|
||||
Action(interval.TotalSeconds);
|
||||
else if (AsyncAction != null)
|
||||
try
|
||||
{
|
||||
Task task = AsyncAction(interval.TotalSeconds);
|
||||
task.Wait();
|
||||
if (Action != null)
|
||||
Action(interval.TotalSeconds);
|
||||
else if (AsyncAction != null)
|
||||
{
|
||||
Task task = AsyncAction(interval.TotalSeconds);
|
||||
task.Wait();
|
||||
}
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
_logger.Error(exception, "Timed update uncaught exception in plugin {plugin}", Feature.Plugin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user