Prevent ProgressMessageTarget from ever reading the command from the database.

pull/3113/head
Taloth Saldono 10 years ago
parent 6d18b37a94
commit 866f971d41

@ -62,7 +62,7 @@ namespace NzbDrone.Api.Commands
{
if (message.Command.Body.SendUpdatesToClient)
{
BroadcastResourceChange(ModelAction.Updated, message.Command.Id);
BroadcastResourceChange(ModelAction.Updated, message.Command.InjectTo<CommandResource>());
}
}
}

@ -69,9 +69,9 @@ namespace NzbDrone.Core.Messaging.Commands
_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 @@ namespace NzbDrone.Core.Messaging.Commands
_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 @@ namespace NzbDrone.Core.Messaging.Commands
_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 @@ namespace NzbDrone.Core.ProgressMessaging
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 @@ namespace NzbDrone.Core.ProgressMessaging
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()
{
var commandId = MappedDiagnosticsContext.Get("CommandId");
if (String.IsNullOrWhiteSpace(commandId))
finally
{
return null;
ProgressMessageContext.UnlockReentrancy();
}
return _commandQueueManager.Get(Convert.ToInt32(commandId));
}
private bool IsClientMessage(LogEventInfo logEvent, CommandModel command)
@ -60,20 +49,6 @@ namespace NzbDrone.Core.ProgressMessaging
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…
Cancel
Save