diff --git a/NzbDrone.Common/Eventing/EventAggregator.cs b/NzbDrone.Common/Eventing/EventAggregator.cs index 86d6c901f..0c6b373ae 100644 --- a/NzbDrone.Common/Eventing/EventAggregator.cs +++ b/NzbDrone.Common/Eventing/EventAggregator.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading.Tasks; using NLog; namespace NzbDrone.Common.Eventing @@ -20,11 +21,25 @@ public void Publish(TEvent message) where TEvent : IEvent { _logger.Trace("Publishing {0}", message.GetType().Name); + //call synchronous handlers first. foreach (var handler in _handlers().OfType>()) { - _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>()) + { + 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); + }); } } } -} \ No newline at end of file +} diff --git a/NzbDrone.Common/Eventing/IHandle.cs b/NzbDrone.Common/Eventing/IHandle.cs index a47df925d..d33a4dc32 100644 --- a/NzbDrone.Common/Eventing/IHandle.cs +++ b/NzbDrone.Common/Eventing/IHandle.cs @@ -9,14 +9,32 @@ namespace NzbDrone.Common.Eventing public interface IHandle : IHandle where TEvent : IEvent { /// - /// Handles the message. + /// Handles the message synchronously. /// /// The message. void Handle(TEvent message); } + /// + /// Denotes a class which can handle a particular type of message. + /// + /// The type of message to handle. + public interface IHandleAsync : IHandleAsync where TEvent : IEvent + { + /// + /// Handles the message asynchronously. + /// + /// The message. + void HandleAsync(TEvent message); + } + /// /// A marker interface for classes that subscribe to messages. /// public interface IHandle { } + + /// + /// A marker interface for classes that subscribe to messages. + /// + public interface IHandleAsync : IHandle { } } \ No newline at end of file diff --git a/NzbDrone.Core/Jobs/Implementations/RefreshEpisodeMetadata.cs b/NzbDrone.Core/Jobs/Implementations/RefreshEpisodeMetadata.cs index f9c430a6a..867d26106 100644 --- a/NzbDrone.Core/Jobs/Implementations/RefreshEpisodeMetadata.cs +++ b/NzbDrone.Core/Jobs/Implementations/RefreshEpisodeMetadata.cs @@ -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); } } } \ No newline at end of file diff --git a/NzbDrone.Core/MediaCover/MediaCoverService.cs b/NzbDrone.Core/MediaCover/MediaCoverService.cs index c048d5bd9..89665f6e1 100644 --- a/NzbDrone.Core/MediaCover/MediaCoverService.cs +++ b/NzbDrone.Core/MediaCover/MediaCoverService.cs @@ -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 + public class MediaCoverService : IHandleAsync { 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); }