Progress messages are logged with Logger.Progress

This commit is contained in:
Mark McDowall 2013-09-03 22:01:28 -07:00
parent a7eb331d4e
commit c184ec2d98
20 changed files with 166 additions and 90 deletions

View File

@ -1,6 +1,8 @@
using System.Collections.Generic;
using Nancy;
using NLog;
using NzbDrone.Api.Mapping;
using NzbDrone.Common.Instrumentation;
using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.Download;
using NzbDrone.Core.IndexerSearch;
@ -21,18 +23,21 @@ namespace NzbDrone.Api.Indexers
private readonly IMakeDownloadDecision _downloadDecisionMaker;
private readonly IDownloadService _downloadService;
private readonly IParsingService _parsingService;
private readonly Logger _logger;
public ReleaseModule(IFetchAndParseRss rssFetcherAndParser,
ISearchForNzb nzbSearchService,
IMakeDownloadDecision downloadDecisionMaker,
IDownloadService downloadService,
IParsingService parsingService)
IParsingService parsingService,
Logger logger)
{
_rssFetcherAndParser = rssFetcherAndParser;
_nzbSearchService = nzbSearchService;
_downloadDecisionMaker = downloadDecisionMaker;
_downloadService = downloadService;
_parsingService = parsingService;
_logger = logger;
GetResourceAll = GetReleases;
Post["/"] = x=> DownloadRelease(this.Bind<ReleaseResource>());
}
@ -60,6 +65,7 @@ namespace NzbDrone.Api.Indexers
private List<ReleaseResource> GetEpisodeReleases(int episodeId)
{
var decisions = _nzbSearchService.EpisodeSearch(episodeId);
return MapDecisions(decisions);
}

View File

@ -9,12 +9,20 @@ namespace NzbDrone.Common.Instrumentation
{
public static class LoggerExtensions
{
public static void Progress(this Logger logger, string message)
{
LogProgressMessage(logger, message, ProcessState.Running);
}
public static void Progress(this Logger logger, string message, params object[] args)
{
var formattedMessage = String.Format(message, args);
Progress(logger, formattedMessage);
}
public static void Complete(this Logger logger, string message)
{
var logEvent = new LogEventInfo(LogLevel.Info, logger.Name, message);
logEvent.Properties.Add("Status", ProcessState.Completed);
logger.Log(logEvent);
LogProgressMessage(logger, message, ProcessState.Completed);
}
public static void Complete(this Logger logger, string message, params object[] args)
@ -25,10 +33,7 @@ namespace NzbDrone.Common.Instrumentation
public static void Failed(this Logger logger, string message)
{
var logEvent = new LogEventInfo(LogLevel.Info, logger.Name, message);
logEvent.Properties.Add("Status", ProcessState.Failed);
logger.Log(logEvent);
LogProgressMessage(logger, message, ProcessState.Failed);
}
public static void Failed(this Logger logger, string message, params object[] args)
@ -36,5 +41,13 @@ namespace NzbDrone.Common.Instrumentation
var formattedMessage = String.Format(message, args);
Failed(logger, formattedMessage);
}
private static void LogProgressMessage(Logger logger, string message, ProcessState state)
{
var logEvent = new LogEventInfo(LogLevel.Info, logger.Name, message);
logEvent.Properties.Add("Status", state);
logger.Log(logEvent);
}
}
}

View File

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using NLog;
using NzbDrone.Common.Instrumentation;
using NzbDrone.Core.DecisionEngine.Specifications.Search;
using NzbDrone.Core.IndexerSearch.Definitions;
using NzbDrone.Core.Parser;
@ -12,8 +13,8 @@ namespace NzbDrone.Core.DecisionEngine
{
public interface IMakeDownloadDecision
{
List<DownloadDecision> GetRssDecision(IEnumerable<ReportInfo> reports);
List<DownloadDecision> GetSearchDecision(IEnumerable<ReportInfo> reports, SearchCriteriaBase searchCriteriaBase);
List<DownloadDecision> GetRssDecision(List<ReportInfo> reports);
List<DownloadDecision> GetSearchDecision(List<ReportInfo> reports, SearchCriteriaBase searchCriteriaBase);
}
public class DownloadDecisionMaker : IMakeDownloadDecision
@ -29,18 +30,28 @@ namespace NzbDrone.Core.DecisionEngine
_logger = logger;
}
public List<DownloadDecision> GetRssDecision(IEnumerable<ReportInfo> reports)
public List<DownloadDecision> GetRssDecision(List<ReportInfo> reports)
{
return GetDecisions(reports).ToList();
}
public List<DownloadDecision> GetSearchDecision(IEnumerable<ReportInfo> reports, SearchCriteriaBase searchCriteriaBase)
public List<DownloadDecision> GetSearchDecision(List<ReportInfo> reports, SearchCriteriaBase searchCriteriaBase)
{
return GetDecisions(reports, searchCriteriaBase).ToList();
}
private IEnumerable<DownloadDecision> GetDecisions(IEnumerable<ReportInfo> reports, SearchCriteriaBase searchCriteria = null)
private IEnumerable<DownloadDecision> GetDecisions(List<ReportInfo> reports, SearchCriteriaBase searchCriteria = null)
{
if (reports.Any())
{
_logger.Progress("Processing {0} reports", reports.Count());
}
else
{
_logger.Progress("No reports found");
}
foreach (var report in reports)
{
DownloadDecision decision = null;

View File

@ -1,4 +1,5 @@
using NLog;
using NzbDrone.Common.Instrumentation;
using NzbDrone.Common.Messaging;
using NzbDrone.Core.Parser.Model;
@ -37,7 +38,7 @@ namespace NzbDrone.Core.Download
downloadClient.DownloadNzb(remoteEpisode);
_logger.Info("Report sent to download client. {0}", downloadTitle);
_logger.Progress("Report sent to download client. {0}", downloadTitle);
_messageAggregator.PublishEvent(new EpisodeGrabbedEvent(remoteEpisode));
}
}

View File

@ -7,7 +7,7 @@ namespace NzbDrone.Core.IndexerSearch.Definitions
public override string ToString()
{
return string.Format("[{0} : S{1:00}E{2:00} ]", SceneTitle, SeasonNumber, EpisodeNumber);
return string.Format("[{0} : S{1:00}E{2:00}]", SceneTitle, SeasonNumber, EpisodeNumber);
}
}
}

View File

@ -1,4 +1,7 @@
using NzbDrone.Common.Messaging;
using System.Linq;
using NLog;
using NzbDrone.Common.Instrumentation;
using NzbDrone.Common.Messaging;
using NzbDrone.Core.Download;
namespace NzbDrone.Core.IndexerSearch
@ -7,17 +10,23 @@ namespace NzbDrone.Core.IndexerSearch
{
private readonly ISearchForNzb _nzbSearchService;
private readonly IDownloadApprovedReports _downloadApprovedReports;
private readonly Logger _logger;
public EpisodeSearchService(ISearchForNzb nzbSearchService, IDownloadApprovedReports downloadApprovedReports)
public EpisodeSearchService(ISearchForNzb nzbSearchService,
IDownloadApprovedReports downloadApprovedReports,
Logger logger)
{
_nzbSearchService = nzbSearchService;
_downloadApprovedReports = downloadApprovedReports;
_logger = logger;
}
public void Execute(EpisodeSearchCommand message)
{
var decisions = _nzbSearchService.EpisodeSearch(message.EpisodeId);
_downloadApprovedReports.DownloadApproved(decisions);
var downloaded = _downloadApprovedReports.DownloadApproved(decisions);
_logger.Complete("Episode search completed. {0} reports downloaded.", downloaded.Count);
}
}
}

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Globalization;
using System.Threading.Tasks;
using NLog;
using NzbDrone.Common.Instrumentation;
using NzbDrone.Core.DataAugmentation.Scene;
using NzbDrone.Core.DecisionEngine;
using NzbDrone.Core.IndexerSearch.Definitions;
@ -129,9 +130,10 @@ namespace NzbDrone.Core.IndexerSearch
private List<DownloadDecision> Dispatch(Func<IIndexer, IEnumerable<ReportInfo>> searchAction, SearchCriteriaBase criteriaBase)
{
var indexers = _indexerService.GetAvailableIndexers().ToList();
_logger.Progress("Searching {0} indexers for {1}", indexers.Count, criteriaBase);
var reports = new List<ReportInfo>();
var taskList = new List<Task>();
var taskFactory = new TaskFactory(TaskCreationOptions.LongRunning, TaskContinuationOptions.None);
@ -159,7 +161,7 @@ namespace NzbDrone.Core.IndexerSearch
Task.WaitAll(taskList.ToArray());
_logger.Debug("Total of {0} reports were found for {1} in {2} indexers", reports.Count, criteriaBase, indexers.Count);
_logger.Debug("Total of {0} reports were found for {1} from {2} indexers", reports.Count, criteriaBase, indexers.Count);
return _makeDownloadDecision.GetSearchDecision(reports, criteriaBase).ToList();
}

View File

@ -1,4 +1,6 @@
using NzbDrone.Common.Messaging;
using NLog;
using NzbDrone.Common.Instrumentation;
using NzbDrone.Common.Messaging;
using NzbDrone.Core.Download;
namespace NzbDrone.Core.IndexerSearch
@ -7,17 +9,23 @@ namespace NzbDrone.Core.IndexerSearch
{
private readonly ISearchForNzb _nzbSearchService;
private readonly IDownloadApprovedReports _downloadApprovedReports;
private readonly Logger _logger;
public SeasonSearchService(ISearchForNzb nzbSearchService, IDownloadApprovedReports downloadApprovedReports)
public SeasonSearchService(ISearchForNzb nzbSearchService,
IDownloadApprovedReports downloadApprovedReports,
Logger logger)
{
_nzbSearchService = nzbSearchService;
_downloadApprovedReports = downloadApprovedReports;
_logger = logger;
}
public void Execute(SeasonSearchCommand message)
{
var decisions = _nzbSearchService.SeasonSearch(message.SeriesId, message.SeasonNumber);
_downloadApprovedReports.DownloadApproved(decisions);
var downloaded = _downloadApprovedReports.DownloadApproved(decisions);
_logger.Complete("Season search completed. {0} reports downloaded.", downloaded.Count);
}
}
}

View File

@ -1,4 +1,6 @@
using System.Linq;
using NLog;
using NzbDrone.Common.Instrumentation;
using NzbDrone.Common.Messaging;
using NzbDrone.Core.Download;
using NzbDrone.Core.Tv;
@ -10,14 +12,17 @@ namespace NzbDrone.Core.IndexerSearch
private readonly ISeasonService _seasonService;
private readonly ISearchForNzb _nzbSearchService;
private readonly IDownloadApprovedReports _downloadApprovedReports;
private readonly Logger _logger;
public SeriesSearchService(ISeasonService seasonService,
ISearchForNzb nzbSearchService,
IDownloadApprovedReports downloadApprovedReports)
IDownloadApprovedReports downloadApprovedReports,
Logger logger)
{
_seasonService = seasonService;
_nzbSearchService = nzbSearchService;
_downloadApprovedReports = downloadApprovedReports;
_logger = logger;
}
public void Execute(SeriesSearchCommand message)
@ -27,11 +32,15 @@ namespace NzbDrone.Core.IndexerSearch
.OrderBy(s => s.SeasonNumber)
.ToList();
var downloadedCount = 0;
foreach (var season in seasons)
{
var decisions = _nzbSearchService.SeasonSearch(message.SeriesId, season.SeasonNumber);
_downloadApprovedReports.DownloadApproved(decisions);
downloadedCount += _downloadApprovedReports.DownloadApproved(decisions).Count;
}
_logger.Complete("Series search completed. {0} reports downloaded.", downloadedCount);
}
}
}

View File

@ -48,7 +48,7 @@ namespace NzbDrone.Core.Indexers
var result = Fetch(indexer, searchCriteria, 0).DistinctBy(c => c.NzbUrl).ToList();
_logger.Info("Finished searching {0} on {1}. Found {2}", indexer.Name, searchCriteria, result.Count);
_logger.Info("Finished searching {0} for {1}. Found {2}", indexer.Name, searchCriteria, result.Count);
return result;
}
@ -80,12 +80,10 @@ namespace NzbDrone.Core.Indexers
var result = Fetch(indexer, searchUrls);
_logger.Info("Finished searching {0} on {1}. Found {2}", indexer.Name, searchCriteria, result.Count);
_logger.Info("Finished searching {0} for {1}. Found {2}", indexer.Name, searchCriteria, result.Count);
return result;
}
public IList<ReportInfo> Fetch(IIndexer indexer, DailyEpisodeSearchCriteria searchCriteria)
{
_logger.Debug("Searching for {0}", searchCriteria);
@ -93,7 +91,7 @@ namespace NzbDrone.Core.Indexers
var searchUrls = indexer.GetDailyEpisodeSearchUrls(searchCriteria.QueryTitle, searchCriteria.SeriesTvRageId, searchCriteria.Airtime);
var result = Fetch(indexer, searchUrls);
_logger.Info("Finished searching {0} on {1}. Found {2}", indexer.Name, searchCriteria, result.Count);
_logger.Info("Finished searching {0} for {1}. Found {2}", indexer.Name, searchCriteria, result.Count);
return result;
}

View File

@ -33,13 +33,13 @@ namespace NzbDrone.Core.Indexers
public void Sync()
{
_logger.Info("Starting RSS Sync");
_logger.Progress("Starting RSS Sync");
var reports = _rssFetcherAndParser.Fetch();
var decisions = _downloadDecisionMaker.GetRssDecision(reports);
var qualifiedReports = _downloadApprovedReports.DownloadApproved(decisions);
var downloaded = _downloadApprovedReports.DownloadApproved(decisions);
_logger.Complete("RSS Sync Completed. Reports found: {0}, Reports downloaded: {1}", reports.Count, qualifiedReports.Count());
_logger.Complete("RSS Sync Completed. Reports found: {0}, Reports downloaded: {1}", reports.Count, downloaded.Count());
}
public void Execute(RssSyncCommand message)

View File

@ -3,6 +3,7 @@ using System.IO;
using System.Linq;
using NLog;
using NzbDrone.Common;
using NzbDrone.Common.Instrumentation;
using NzbDrone.Common.Messaging;
using NzbDrone.Core.MediaFiles.Commands;
using NzbDrone.Core.MediaFiles.EpisodeImport;
@ -52,6 +53,7 @@ namespace NzbDrone.Core.MediaFiles
private void Scan(Series series)
{
_logger.Progress("Starting disk scan for {0}", series.Title);
_messageAggregator.PublishCommand(new CleanMediaFileDb(series.Id));
if (!_diskProvider.FolderExists(series.Path))
@ -64,6 +66,8 @@ namespace NzbDrone.Core.MediaFiles
var decisions = _importDecisionMaker.GetImportDecisions(mediaFileList, series, false);
_importApprovedEpisodes.Import(decisions);
_logger.Complete("Completed disk scan for {0}", series.Title);
}
public string[] GetVideoFiles(string path, bool allDirectories = true)

View File

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using NLog;
using NzbDrone.Common.Instrumentation;
using NzbDrone.Common.Messaging;
using NzbDrone.Core.MediaFiles.Commands;
using NzbDrone.Core.MediaFiles.Events;
@ -67,9 +68,9 @@ namespace NzbDrone.Core.MediaFiles
var series = _seriesService.GetSeries(message.SeriesId);
var episodeFiles = _mediaFileService.GetFilesBySeason(message.SeriesId, message.SeasonNumber);
_logger.Info("Renaming {0} files for {1} season {2}", episodeFiles.Count, series.Title, message.SeasonNumber);
_logger.Progress("Renaming {0} files for {1} season {2}", episodeFiles.Count, series.Title, message.SeasonNumber);
RenameFiles(episodeFiles, series);
_logger.Debug("Episode Fies renamed for {0} season {1}", series.Title, message.SeasonNumber);
_logger.Complete("Episode Fies renamed for {0} season {1}", series.Title, message.SeasonNumber);
}
public void Execute(RenameSeriesCommand message)
@ -77,9 +78,9 @@ namespace NzbDrone.Core.MediaFiles
var series = _seriesService.GetSeries(message.SeriesId);
var episodeFiles = _mediaFileService.GetFilesBySeries(message.SeriesId);
_logger.Info("Renaming {0} files for {1}", episodeFiles.Count, series.Title);
_logger.Progress("Renaming {0} files for {1}", episodeFiles.Count, series.Title);
RenameFiles(episodeFiles, series);
_logger.Debug("Episode Fies renamed for {0}", series.Title);
_logger.Complete("Episode Fies renamed for {0}", series.Title);
}
}
}

View File

@ -56,7 +56,12 @@ namespace NzbDrone.Core.ProgressMessaging
return;
}
var status = logEvent.Properties.ContainsKey("Status") ? (ProcessState)logEvent.Properties["Status"] : ProcessState.Running;
if (!logEvent.Properties.ContainsKey("Status"))
{
return;
}
var status = (ProcessState)logEvent.Properties["Status"];
var message = new ProgressMessage();
message.Time = logEvent.TimeStamp;

View File

@ -129,7 +129,7 @@ namespace NzbDrone.Core.Tv
var episode = _episodeRepository.Get(episodeId);
_episodeRepository.SetMonitoredFlat(episode, monitored);
logger.Info("Monitored flag for Episode:{0} was set to {1}", episodeId, monitored);
logger.Debug("Monitored flag for Episode:{0} was set to {1}", episodeId, monitored);
}
public void SetEpisodeMonitoredBySeason(int seriesId, int seasonNumber, bool monitored)

View File

@ -30,7 +30,7 @@ namespace NzbDrone.Core.Tv
public void RefreshEpisodeInfo(Series series, IEnumerable<Episode> remoteEpisodes)
{
_logger.Info("Starting series info refresh for: {0}", series);
_logger.Info("Starting episode info refresh for: {0}", series);
var successCount = 0;
var failCount = 0;

View File

@ -2,6 +2,7 @@
using System.IO;
using System.Linq;
using NLog;
using NzbDrone.Common.Instrumentation;
using NzbDrone.Common.Messaging;
using NzbDrone.Core.DataAugmentation.DailySeries;
using NzbDrone.Core.MetadataSource;
@ -30,39 +31,9 @@ namespace NzbDrone.Core.Tv
_logger = logger;
}
public void Execute(RefreshSeriesCommand message)
{
if (message.SeriesId.HasValue)
{
var series = _seriesService.GetSeries(message.SeriesId.Value);
RefreshSeriesInfo(series);
}
else
{
var allSeries = _seriesService.GetAllSeries().OrderBy(c => c.LastInfoSync).ToList();
foreach (var series in allSeries)
{
try
{
RefreshSeriesInfo(series);
}
catch (Exception e)
{
_logger.ErrorException("Couldn't refresh info for {0}".Inject(series), e);
}
}
}
}
public void HandleAsync(SeriesAddedEvent message)
{
RefreshSeriesInfo(message.Series);
}
private void RefreshSeriesInfo(Series series)
{
_logger.Progress("Starting Series Refresh for {0}", series.Title);
var tuple = _seriesInfo.GetSeriesInfo(series.TvdbId);
var seriesInfo = tuple.Item1;
@ -96,7 +67,38 @@ namespace NzbDrone.Core.Tv
_seriesService.UpdateSeries(series);
_refreshEpisodeService.RefreshEpisodeInfo(series, tuple.Item2);
_logger.Complete("Finished series refresh for {0}", series.Title);
_messageAggregator.PublishEvent(new SeriesUpdatedEvent(series));
}
public void Execute(RefreshSeriesCommand message)
{
if (message.SeriesId.HasValue)
{
var series = _seriesService.GetSeries(message.SeriesId.Value);
RefreshSeriesInfo(series);
}
else
{
var allSeries = _seriesService.GetAllSeries().OrderBy(c => c.LastInfoSync).ToList();
foreach (var series in allSeries)
{
try
{
RefreshSeriesInfo(series);
}
catch (Exception e)
{
_logger.ErrorException("Couldn't refresh info for {0}".Inject(series), e);
}
}
}
}
public void HandleAsync(SeriesAddedEvent message)
{
RefreshSeriesInfo(message.Series);
}
}
}

View File

@ -47,11 +47,10 @@ define(
Actioneer.ExecuteCommand({
command : 'episodeSearch',
properties : {
properties: {
episodeId: this.model.get('id')
},
errorMessage: 'Search failed for: ' + message,
startMessage: 'Search started for: ' + message
errorMessage: 'Search failed for: ' + message
});
App.vent.trigger(App.Commands.CloseModalCommand);

View File

@ -17,11 +17,13 @@ define(
collection.signalRconnection.received(function (message) {
var type = getMessengerType(message.status);
var hideAfter = type === 'info' ? 60 : 5;
Messenger.show({
id : message.commandId,
message: message.message,
type : type
message : message.message,
type : type,
hideAfter: hideAfter
});
});

View File

@ -92,6 +92,10 @@ define(
},
_getIconClass: function(element) {
if (!element) {
return '';
}
return element.attr('class').match(/(?:^|\s)icon\-.+?(?:$|\s)/)[0];
},
@ -143,6 +147,7 @@ define(
options.button.removeClass('disable');
}
if (options.element) {
if (options.leaveIcon) {
options.element.removeClass('icon-spin');
}
@ -152,6 +157,7 @@ define(
options.element.removeClass('icon-nd-spinner');
options.element.removeClass('icon-spin');
}
}
if (options.always) {
options.always.call(options.context);