mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-04 10:02:40 +01:00
Prevent ProgressMessageTarget from ever reading the command from the database.
This commit is contained in:
parent
6d18b37a94
commit
866f971d41
@ -62,7 +62,7 @@ public void Handle(CommandUpdatedEvent message)
|
||||
{
|
||||
if (message.Command.Body.SendUpdatesToClient)
|
||||
{
|
||||
BroadcastResourceChange(ModelAction.Updated, message.Command.Id);
|
||||
BroadcastResourceChange(ModelAction.Updated, message.Command.InjectTo<CommandResource>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -69,9 +69,9 @@ private void ExecuteCommand<TCommand>(TCommand command, CommandModel commandMode
|
||||
_commandQueueManager.Start(commandModel);
|
||||
BroadcastCommandUpdate(commandModel);
|
||||
|
||||
if (!MappedDiagnosticsContext.Contains("CommandId"))
|
||||
if (ProgressMessageContext.CommandModel == null)
|
||||
{
|
||||
MappedDiagnosticsContext.Set("CommandId", commandModel.Id.ToString());
|
||||
ProgressMessageContext.CommandModel = commandModel;
|
||||
}
|
||||
|
||||
handler.Execute(command);
|
||||
@ -96,9 +96,9 @@ private void ExecuteCommand<TCommand>(TCommand command, CommandModel commandMode
|
||||
|
||||
_eventAggregator.PublishEvent(new CommandExecutedEvent(commandModel));
|
||||
|
||||
if (MappedDiagnosticsContext.Get("CommandId") == commandModel.Id.ToString())
|
||||
if (ProgressMessageContext.CommandModel == commandModel)
|
||||
{
|
||||
MappedDiagnosticsContext.Remove("CommandId");
|
||||
ProgressMessageContext.CommandModel = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,8 +80,8 @@ public CommandModel Push<TCommand>(TCommand command, CommandPriority priority =
|
||||
_logger.Trace("Inserting new command: {0}", commandModel.Name);
|
||||
|
||||
_repo.Insert(commandModel);
|
||||
_commandQueue.Add(commandModel);
|
||||
_commandCache.Set(commandModel.Id.ToString(), commandModel);
|
||||
_commandQueue.Add(commandModel);
|
||||
|
||||
return commandModel;
|
||||
}
|
||||
|
@ -717,6 +717,7 @@
|
||||
<Compile Include="Profiles\Delay\DelayProfileService.cs" />
|
||||
<Compile Include="Profiles\Delay\DelayProfileTagInUseValidator.cs" />
|
||||
<Compile Include="Profiles\ProfileRepository.cs" />
|
||||
<Compile Include="ProgressMessaging\ProgressMessageContext.cs" />
|
||||
<Compile Include="Qualities\Revision.cs" />
|
||||
<Compile Include="RemotePathMappings\RemotePathMapping.cs" />
|
||||
<Compile Include="RemotePathMappings\RemotePathMappingRepository.cs" />
|
||||
|
@ -0,0 +1,37 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NzbDrone.Core.Messaging.Commands;
|
||||
|
||||
namespace NzbDrone.Core.ProgressMessaging
|
||||
{
|
||||
public static class ProgressMessageContext
|
||||
{
|
||||
[ThreadStatic]
|
||||
private static CommandModel _commandModel;
|
||||
|
||||
[ThreadStatic]
|
||||
private static bool _reentrancyLock;
|
||||
|
||||
public static CommandModel CommandModel
|
||||
{
|
||||
get { return _commandModel; }
|
||||
set { _commandModel = value; }
|
||||
}
|
||||
|
||||
public static bool LockReentrancy()
|
||||
{
|
||||
if (_reentrancyLock)
|
||||
return false;
|
||||
|
||||
_reentrancyLock = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void UnlockReentrancy()
|
||||
{
|
||||
_reentrancyLock = false;
|
||||
}
|
||||
}
|
||||
}
|
@ -15,8 +15,6 @@ public class ProgressMessageTarget : Target, IHandle<ApplicationStartedEvent>
|
||||
private readonly IManageCommandQueue _commandQueueManager;
|
||||
private static LoggingRule _rule;
|
||||
|
||||
private const string REENTRY_LOCK = "ProgressMessagingLock";
|
||||
|
||||
public ProgressMessageTarget(IEventAggregator eventAggregator, IManageCommandQueue commandQueueManager)
|
||||
{
|
||||
_eventAggregator = eventAggregator;
|
||||
@ -25,29 +23,20 @@ public ProgressMessageTarget(IEventAggregator eventAggregator, IManageCommandQue
|
||||
|
||||
protected override void Write(LogEventInfo logEvent)
|
||||
{
|
||||
if (!ReentryPreventionCheck()) return;
|
||||
var command = ProgressMessageContext.CommandModel;
|
||||
|
||||
var command = GetCurrentCommand();
|
||||
if (!IsClientMessage(logEvent, command)) return;
|
||||
|
||||
if (IsClientMessage(logEvent, command))
|
||||
if (!ProgressMessageContext.LockReentrancy()) return;
|
||||
try
|
||||
{
|
||||
_commandQueueManager.SetMessage(command, logEvent.FormattedMessage);
|
||||
_eventAggregator.PublishEvent(new CommandUpdatedEvent(command));
|
||||
}
|
||||
|
||||
MappedDiagnosticsContext.Remove(REENTRY_LOCK);
|
||||
}
|
||||
|
||||
private CommandModel GetCurrentCommand()
|
||||
finally
|
||||
{
|
||||
var commandId = MappedDiagnosticsContext.Get("CommandId");
|
||||
|
||||
if (String.IsNullOrWhiteSpace(commandId))
|
||||
{
|
||||
return null;
|
||||
ProgressMessageContext.UnlockReentrancy();
|
||||
}
|
||||
|
||||
return _commandQueueManager.Get(Convert.ToInt32(commandId));
|
||||
}
|
||||
|
||||
private bool IsClientMessage(LogEventInfo logEvent, CommandModel command)
|
||||
@ -60,20 +49,6 @@ private bool IsClientMessage(LogEventInfo logEvent, CommandModel command)
|
||||
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)
|
||||
{
|
||||
_rule = new LoggingRule("*", LogLevel.Trace, this);
|
||||
|
Loading…
Reference in New Issue
Block a user