From 13f540f1f5c5e6b7e075d00c868f3163d9707153 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Wed, 2 May 2018 23:34:05 -0700 Subject: [PATCH] Fixed: Rescan series if refresh fails Closes #2540 --- .../TvTests/RefreshSeriesServiceFixture.cs | 35 ++++++++++++++++- src/NzbDrone.Core/Tv/RefreshSeriesService.cs | 38 +++++++++++++------ 2 files changed, 61 insertions(+), 12 deletions(-) diff --git a/src/NzbDrone.Core.Test/TvTests/RefreshSeriesServiceFixture.cs b/src/NzbDrone.Core.Test/TvTests/RefreshSeriesServiceFixture.cs index 1012149c1..31c402927 100644 --- a/src/NzbDrone.Core.Test/TvTests/RefreshSeriesServiceFixture.cs +++ b/src/NzbDrone.Core.Test/TvTests/RefreshSeriesServiceFixture.cs @@ -1,11 +1,14 @@ -using System; +using System; using System.Collections.Generic; +using System.IO; using System.Linq; using FizzWare.NBuilder; +using FluentAssertions; using Moq; using NUnit.Framework; using NzbDrone.Common.Extensions; using NzbDrone.Core.Exceptions; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.MetadataSource; using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Tv; @@ -180,5 +183,35 @@ public void should_filter_duplicate_seasons() .Verify(v => v.UpdateSeries(It.Is(s => s.Seasons.Count == 2), It.IsAny())); } + + [Test] + public void should_rescan_series_if_updating_fails() + { + Mocker.GetMock() + .Setup(s => s.GetSeriesInfo(_series.Id)) + .Throws(new IOException()); + + Assert.Throws(() => Subject.Execute(new RefreshSeriesCommand(_series.Id))); + + Mocker.GetMock() + .Verify(v => v.Scan(_series), Times.Once()); + + ExceptionVerification.ExpectedErrors(1); + } + + [Test] + public void should_not_rescan_series_if_updating_fails_with_series_not_found() + { + Mocker.GetMock() + .Setup(s => s.GetSeriesInfo(_series.Id)) + .Throws(new SeriesNotFoundException(_series.Id)); + + Subject.Execute(new RefreshSeriesCommand(_series.Id)); + + Mocker.GetMock() + .Verify(v => v.Scan(_series), Times.Never()); + + ExceptionVerification.ExpectedErrors(1); + } } } diff --git a/src/NzbDrone.Core/Tv/RefreshSeriesService.cs b/src/NzbDrone.Core/Tv/RefreshSeriesService.cs index f177b5857..a7f42f554 100644 --- a/src/NzbDrone.Core/Tv/RefreshSeriesService.cs +++ b/src/NzbDrone.Core/Tv/RefreshSeriesService.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -144,6 +144,18 @@ private List UpdateSeasons(Series series, Series seriesInfo) return seasons; } + private void RescanSeries(Series series) + { + try + { + _diskScanService.Scan(series); + } + catch (Exception e) + { + _logger.Error(e, "Couldn't rescan series {0}", series); + } + } + public void Execute(RefreshSeriesCommand message) { _eventAggregator.PublishEvent(new SeriesRefreshStartingEvent(message.Trigger == CommandTrigger.Manual)); @@ -151,7 +163,17 @@ public void Execute(RefreshSeriesCommand message) if (message.SeriesId.HasValue) { var series = _seriesService.GetSeries(message.SeriesId.Value); - RefreshSeriesInfo(series); + + try + { + RefreshSeriesInfo(series); + } + catch (Exception e) + { + _logger.Error(e, "Couldn't refresh info for {0}", series); + RescanSeries(series); + throw; + } } else { @@ -168,20 +190,14 @@ public void Execute(RefreshSeriesCommand message) catch (Exception e) { _logger.Error(e, "Couldn't refresh info for {0}", series); + RescanSeries(series); } } else { - try - { - _logger.Info("Skipping refresh of series: {0}", series.Title); - _diskScanService.Scan(series); - } - catch (Exception e) - { - _logger.Error(e, "Couldn't rescan series {0}", series); - } + _logger.Info("Skipping refresh of series: {0}", series.Title); + RescanSeries(series); } } }