mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-21 14:03:29 -07:00
more granular Concurrency control.
indexer calls are done fully paralleled. events are dispatched on max of 2 threads.
This commit is contained in:
parent
763df726f0
commit
9181b1bb91
12 changed files with 377 additions and 37 deletions
|
@ -1,6 +1,5 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using NLog;
|
||||
using NzbDrone.Common.EnsureThat;
|
||||
|
@ -12,11 +11,14 @@ namespace NzbDrone.Common.Messaging
|
|||
{
|
||||
private readonly Logger _logger;
|
||||
private readonly IServiceFactory _serviceFactory;
|
||||
private readonly TaskFactory _taskFactory;
|
||||
|
||||
public MessageAggregator(Logger logger, IServiceFactory serviceFactory)
|
||||
{
|
||||
_logger = logger;
|
||||
_serviceFactory = serviceFactory;
|
||||
var scheduler = new LimitedConcurrencyLevelTaskScheduler(2);
|
||||
_taskFactory = new TaskFactory(scheduler);
|
||||
}
|
||||
|
||||
public void PublishEvent<TEvent>(TEvent @event) where TEvent : class ,IEvent
|
||||
|
@ -45,12 +47,13 @@ namespace NzbDrone.Common.Messaging
|
|||
foreach (var handler in _serviceFactory.BuildAll<IHandleAsync<TEvent>>())
|
||||
{
|
||||
var handlerLocal = handler;
|
||||
Task.Factory.StartNew(() =>
|
||||
|
||||
_taskFactory.StartNew(() =>
|
||||
{
|
||||
_logger.Debug("{0} ~> {1}", eventName, handlerLocal.GetType().Name);
|
||||
handlerLocal.HandleAsync(@event);
|
||||
_logger.Debug("{0} <~ {1}", eventName, handlerLocal.GetType().Name);
|
||||
});
|
||||
}, TaskCreationOptions.PreferFairness);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue