mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-04 10:02:40 +01:00
Added IHandleAsync, these handlers will be run async and in parallel to each other.
This commit is contained in:
parent
333a88ebd1
commit
d1ba892e45
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using NLog;
|
||||
|
||||
namespace NzbDrone.Common.Eventing
|
||||
@ -20,10 +21,24 @@ public void Publish<TEvent>(TEvent message) where TEvent : IEvent
|
||||
{
|
||||
_logger.Trace("Publishing {0}", message.GetType().Name);
|
||||
|
||||
//call synchronous handlers first.
|
||||
foreach (var handler in _handlers().OfType<IHandle<TEvent>>())
|
||||
{
|
||||
_logger.Trace("{0} => {1}", message.GetType().Name, handler.GetType().Name);
|
||||
_logger.Debug("{0} -> {1}", message.GetType().Name, handler.GetType().Name);
|
||||
handler.Handle(message);
|
||||
_logger.Debug("{0} -#> {1}", message.GetType().Name, handler.GetType().Name);
|
||||
}
|
||||
|
||||
|
||||
foreach (var handler in _handlers().OfType<IHandleAsync<TEvent>>())
|
||||
{
|
||||
var handlerLocal = handler;
|
||||
Task.Factory.StartNew(() =>
|
||||
{
|
||||
_logger.Debug("{0} ~> {1}", message.GetType().Name, handlerLocal.GetType().Name);
|
||||
handlerLocal.HandleAsync(message);
|
||||
_logger.Debug("{0} ~#> {1}", message.GetType().Name, handlerLocal.GetType().Name);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,14 +9,32 @@ namespace NzbDrone.Common.Eventing
|
||||
public interface IHandle<TEvent> : IHandle where TEvent : IEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles the message.
|
||||
/// Handles the message synchronously.
|
||||
/// </summary>
|
||||
/// <param name = "message">The message.</param>
|
||||
void Handle(TEvent message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Denotes a class which can handle a particular type of message.
|
||||
/// </summary>
|
||||
/// <typeparam name = "TEvent">The type of message to handle.</typeparam>
|
||||
public interface IHandleAsync<TEvent> : IHandleAsync where TEvent : IEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles the message asynchronously.
|
||||
/// </summary>
|
||||
/// <param name = "message">The message.</param>
|
||||
void HandleAsync(TEvent message);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A marker interface for classes that subscribe to messages.
|
||||
/// </summary>
|
||||
public interface IHandle { }
|
||||
|
||||
/// <summary>
|
||||
/// A marker interface for classes that subscribe to messages.
|
||||
/// </summary>
|
||||
public interface IHandleAsync : IHandle { }
|
||||
}
|
@ -63,7 +63,7 @@ private void RefreshMetadata(ProgressNotification notification, Series series)
|
||||
return;
|
||||
}
|
||||
|
||||
notification.CurrentMessage = String.Format("Epsiode metadata refresh completed for {0}", series.Title);
|
||||
notification.CurrentMessage = String.Format("Episode metadata refresh completed for {0}", series.Title);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.Eventing;
|
||||
@ -9,7 +10,7 @@
|
||||
|
||||
namespace NzbDrone.Core.MediaCover
|
||||
{
|
||||
public class MediaCoverService : IHandle<SeriesUpdatedEvent>
|
||||
public class MediaCoverService : IHandleAsync<SeriesUpdatedEvent>
|
||||
{
|
||||
private readonly HttpProvider _httpProvider;
|
||||
private readonly DiskProvider _diskProvider;
|
||||
@ -28,7 +29,7 @@ public MediaCoverService(HttpProvider httpProvider, DiskProvider diskProvider, E
|
||||
_coverRootFolder = environmentProvider.GetMediaCoverPath();
|
||||
}
|
||||
|
||||
public void Handle(SeriesUpdatedEvent message)
|
||||
public void HandleAsync(SeriesUpdatedEvent message)
|
||||
{
|
||||
EnsureCovers(message.Series);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user