mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-31 17:53:32 +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.Threading.Tasks;
|
||||||
using System.Timers;
|
using System.Timers;
|
||||||
using Artemis.Core.Modules;
|
using Artemis.Core.Modules;
|
||||||
|
using Artemis.Core.Services;
|
||||||
|
using Ninject;
|
||||||
|
using Serilog;
|
||||||
|
|
||||||
namespace Artemis.Core
|
namespace Artemis.Core
|
||||||
{
|
{
|
||||||
@ -14,9 +17,12 @@ namespace Artemis.Core
|
|||||||
private Timer? _timer;
|
private Timer? _timer;
|
||||||
private bool _disposed;
|
private bool _disposed;
|
||||||
private readonly object _lock = new();
|
private readonly object _lock = new();
|
||||||
|
private ILogger _logger;
|
||||||
|
|
||||||
internal TimedUpdateRegistration(PluginFeature feature, TimeSpan interval, Action<double> action)
|
internal TimedUpdateRegistration(PluginFeature feature, TimeSpan interval, Action<double> action)
|
||||||
{
|
{
|
||||||
|
_logger = CoreService.Kernel.Get<ILogger>();
|
||||||
|
|
||||||
Feature = feature;
|
Feature = feature;
|
||||||
Interval = interval;
|
Interval = interval;
|
||||||
Action = action;
|
Action = action;
|
||||||
@ -119,12 +125,19 @@ namespace Artemis.Core
|
|||||||
if (Feature is Module module && !module.IsUpdateAllowed)
|
if (Feature is Module module && !module.IsUpdateAllowed)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (Action != null)
|
try
|
||||||
Action(interval.TotalSeconds);
|
|
||||||
else if (AsyncAction != null)
|
|
||||||
{
|
{
|
||||||
Task task = AsyncAction(interval.TotalSeconds);
|
if (Action != null)
|
||||||
task.Wait();
|
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