From f3be5fa08edd47e3aaa1e4f886e94d809a475860 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Mon, 23 May 2011 17:44:44 -0700 Subject: [PATCH] failed disk scan doesn't kill the whole job anymore --- NzbDrone.Core.Test/DiskScanJobTest.cs | 31 +++++++++++++++++++++ NzbDrone.Core/Providers/Jobs/DiskScanJob.cs | 15 ++++++++-- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/NzbDrone.Core.Test/DiskScanJobTest.cs b/NzbDrone.Core.Test/DiskScanJobTest.cs index a11d119ee..6022d6604 100644 --- a/NzbDrone.Core.Test/DiskScanJobTest.cs +++ b/NzbDrone.Core.Test/DiskScanJobTest.cs @@ -1,4 +1,5 @@ // ReSharper disable RedundantUsingDirective +using System; using System.Linq; using System.Collections.Generic; using System.Threading; @@ -95,6 +96,36 @@ namespace NzbDrone.Core.Test mocker.VerifyAllMocks(); } + [Test] + public void failed_scan_should_not_terminated_job() + { + var series = Builder.CreateListOfSize(2) + .WhereTheFirst(1).Has(s => s.SeriesId = 12) + .AndTheNext(1).Has(s => s.SeriesId = 15) + .WhereAll().Have(s => s.Episodes = Builder.CreateListOfSize(10).Build()) + .Build(); + + var mocker = new AutoMoqer(MockBehavior.Strict); + + mocker.GetMock() + .Setup(p => p.GetAllSeries()) + .Returns(series.AsQueryable()); + + mocker.GetMock() + .Setup(s => s.Scan(series[0])) + .Throws(new InvalidOperationException("Bad Job")); + + mocker.GetMock() + .Setup(s => s.Scan(series[1])) + .Throws(new InvalidOperationException("Bad Job")); + + mocker.Resolve().Start(new ProgressNotification("Test"), 0); + + + mocker.VerifyAllMocks(); + ExceptionVerification.ExcpectedErrors(2); + } + [Test] public void job_with_no_target_should_scan_series_with_episodes() { diff --git a/NzbDrone.Core/Providers/Jobs/DiskScanJob.cs b/NzbDrone.Core/Providers/Jobs/DiskScanJob.cs index 2e9029e8d..12ec61781 100644 --- a/NzbDrone.Core/Providers/Jobs/DiskScanJob.cs +++ b/NzbDrone.Core/Providers/Jobs/DiskScanJob.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using NLog; using NzbDrone.Core.Model.Notification; using NzbDrone.Core.Repository; @@ -11,6 +12,7 @@ namespace NzbDrone.Core.Providers.Jobs { private readonly SeriesProvider _seriesProvider; private readonly MediaFileProvider _mediaFileProvider; + private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); public DiskScanJob(SeriesProvider seriesProvider, MediaFileProvider mediaFileProvider) { @@ -46,9 +48,16 @@ namespace NzbDrone.Core.Providers.Jobs foreach (var series in seriesToScan.Where(c => c.Episodes.Count != 0)) { - notification.CurrentMessage = string.Format("Scanning disk for '{0}'", series.Title); - _mediaFileProvider.Scan(series); - notification.CurrentMessage = string.Format("Media File Scan completed for '{0}'", series.Title); + try + { + notification.CurrentMessage = string.Format("Scanning disk for '{0}'", series.Title); + _mediaFileProvider.Scan(series); + notification.CurrentMessage = string.Format("Media File Scan completed for '{0}'", series.Title); + } + catch (Exception e) + { + Logger.ErrorException("An error has occured while scanning " + series.Title, e); + } } } }