mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-09 04:22:30 +01:00
Fixed: DB locking due to Progress Messaging
This commit is contained in:
parent
c12f16b6d3
commit
e304a615d0
@ -5,6 +5,7 @@
|
|||||||
using NLog.Config;
|
using NLog.Config;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NLog.Targets;
|
using NLog.Targets;
|
||||||
|
using NLog.Targets.Wrappers;
|
||||||
using NzbDrone.Common.Instrumentation;
|
using NzbDrone.Common.Instrumentation;
|
||||||
using NzbDrone.Core.Datastore;
|
using NzbDrone.Core.Datastore;
|
||||||
using NzbDrone.Core.Lifecycle;
|
using NzbDrone.Core.Lifecycle;
|
||||||
@ -12,7 +13,6 @@
|
|||||||
|
|
||||||
namespace NzbDrone.Core.Instrumentation
|
namespace NzbDrone.Core.Instrumentation
|
||||||
{
|
{
|
||||||
|
|
||||||
public class DatabaseTarget : TargetWithLayout, IHandle<ApplicationShutdownRequested>
|
public class DatabaseTarget : TargetWithLayout, IHandle<ApplicationShutdownRequested>
|
||||||
{
|
{
|
||||||
private readonly SQLiteConnection _connection;
|
private readonly SQLiteConnection _connection;
|
||||||
@ -30,7 +30,7 @@ public void Register()
|
|||||||
{
|
{
|
||||||
Rule = new LoggingRule("*", LogLevel.Info, this);
|
Rule = new LoggingRule("*", LogLevel.Info, this);
|
||||||
|
|
||||||
LogManager.Configuration.AddTarget("DbLogger", this);
|
LogManager.Configuration.AddTarget("DbLogger", new AsyncTargetWrapper(this));
|
||||||
LogManager.Configuration.LoggingRules.Add(Rule);
|
LogManager.Configuration.LoggingRules.Add(Rule);
|
||||||
LogManager.ConfigurationReloaded += OnLogManagerOnConfigurationReloaded;
|
LogManager.ConfigurationReloaded += OnLogManagerOnConfigurationReloaded;
|
||||||
LogManager.ReconfigExistingLoggers();
|
LogManager.ReconfigExistingLoggers();
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
using NLog.Config;
|
using NLog.Config;
|
||||||
using NLog;
|
using NLog;
|
||||||
using NLog.Targets;
|
using NLog.Targets;
|
||||||
|
using NzbDrone.Common.Extensions;
|
||||||
using NzbDrone.Core.Lifecycle;
|
using NzbDrone.Core.Lifecycle;
|
||||||
using NzbDrone.Core.Messaging.Commands;
|
using NzbDrone.Core.Messaging.Commands;
|
||||||
using NzbDrone.Core.Messaging.Events;
|
using NzbDrone.Core.Messaging.Events;
|
||||||
@ -14,6 +15,8 @@ public class ProgressMessageTarget : Target, IHandle<ApplicationStartedEvent>
|
|||||||
private readonly IManageCommandQueue _commandQueueManager;
|
private readonly IManageCommandQueue _commandQueueManager;
|
||||||
private static LoggingRule _rule;
|
private static LoggingRule _rule;
|
||||||
|
|
||||||
|
private const string REENTRY_LOCK = "ProgressMessagingLock";
|
||||||
|
|
||||||
public ProgressMessageTarget(IEventAggregator eventAggregator, IManageCommandQueue commandQueueManager)
|
public ProgressMessageTarget(IEventAggregator eventAggregator, IManageCommandQueue commandQueueManager)
|
||||||
{
|
{
|
||||||
_eventAggregator = eventAggregator;
|
_eventAggregator = eventAggregator;
|
||||||
@ -22,6 +25,8 @@ public ProgressMessageTarget(IEventAggregator eventAggregator, IManageCommandQue
|
|||||||
|
|
||||||
protected override void Write(LogEventInfo logEvent)
|
protected override void Write(LogEventInfo logEvent)
|
||||||
{
|
{
|
||||||
|
if (!ReentryPreventionCheck()) return;
|
||||||
|
|
||||||
var command = GetCurrentCommand();
|
var command = GetCurrentCommand();
|
||||||
|
|
||||||
if (IsClientMessage(logEvent, command))
|
if (IsClientMessage(logEvent, command))
|
||||||
@ -29,6 +34,8 @@ protected override void Write(LogEventInfo logEvent)
|
|||||||
_commandQueueManager.SetMessage(command, logEvent.FormattedMessage);
|
_commandQueueManager.SetMessage(command, logEvent.FormattedMessage);
|
||||||
_eventAggregator.PublishEvent(new CommandUpdatedEvent(command));
|
_eventAggregator.PublishEvent(new CommandUpdatedEvent(command));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MappedDiagnosticsContext.Remove(REENTRY_LOCK);
|
||||||
}
|
}
|
||||||
|
|
||||||
private CommandModel GetCurrentCommand()
|
private CommandModel GetCurrentCommand()
|
||||||
@ -53,6 +60,20 @@ private bool IsClientMessage(LogEventInfo logEvent, CommandModel command)
|
|||||||
return logEvent.Properties.ContainsKey("Status");
|
return logEvent.Properties.ContainsKey("Status");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool ReentryPreventionCheck()
|
||||||
|
{
|
||||||
|
var reentryLock = MappedDiagnosticsContext.Get(REENTRY_LOCK);
|
||||||
|
var commandId = MappedDiagnosticsContext.Get("CommandId");
|
||||||
|
|
||||||
|
if (reentryLock.IsNullOrWhiteSpace() || reentryLock != commandId)
|
||||||
|
{
|
||||||
|
MappedDiagnosticsContext.Set(REENTRY_LOCK, MappedDiagnosticsContext.Get("CommandId"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public void Handle(ApplicationStartedEvent message)
|
public void Handle(ApplicationStartedEvent message)
|
||||||
{
|
{
|
||||||
_rule = new LoggingRule("*", LogLevel.Trace, this);
|
_rule = new LoggingRule("*", LogLevel.Trace, this);
|
||||||
|
Loading…
Reference in New Issue
Block a user