1
0
Fork 0
mirror of https://github.com/Sonarr/Sonarr synced 2024-12-29 03:05:49 +00:00

Fixed: Rescan series if refresh fails

Closes #2540
This commit is contained in:
Mark McDowall 2018-05-02 23:34:05 -07:00
parent a7aff3bd9a
commit 13f540f1f5
2 changed files with 61 additions and 12 deletions

View file

@ -1,11 +1,14 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Linq; using System.Linq;
using FizzWare.NBuilder; using FizzWare.NBuilder;
using FluentAssertions;
using Moq; using Moq;
using NUnit.Framework; using NUnit.Framework;
using NzbDrone.Common.Extensions; using NzbDrone.Common.Extensions;
using NzbDrone.Core.Exceptions; using NzbDrone.Core.Exceptions;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Core.MetadataSource; using NzbDrone.Core.MetadataSource;
using NzbDrone.Core.Test.Framework; using NzbDrone.Core.Test.Framework;
using NzbDrone.Core.Tv; using NzbDrone.Core.Tv;
@ -180,5 +183,35 @@ namespace NzbDrone.Core.Test.TvTests
.Verify(v => v.UpdateSeries(It.Is<Series>(s => s.Seasons.Count == 2), It.IsAny<bool>())); .Verify(v => v.UpdateSeries(It.Is<Series>(s => s.Seasons.Count == 2), It.IsAny<bool>()));
} }
[Test]
public void should_rescan_series_if_updating_fails()
{
Mocker.GetMock<IProvideSeriesInfo>()
.Setup(s => s.GetSeriesInfo(_series.Id))
.Throws(new IOException());
Assert.Throws<IOException>(() => Subject.Execute(new RefreshSeriesCommand(_series.Id)));
Mocker.GetMock<IDiskScanService>()
.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<IProvideSeriesInfo>()
.Setup(s => s.GetSeriesInfo(_series.Id))
.Throws(new SeriesNotFoundException(_series.Id));
Subject.Execute(new RefreshSeriesCommand(_series.Id));
Mocker.GetMock<IDiskScanService>()
.Verify(v => v.Scan(_series), Times.Never());
ExceptionVerification.ExpectedErrors(1);
}
} }
} }

View file

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@ -144,6 +144,18 @@ namespace NzbDrone.Core.Tv
return seasons; 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) public void Execute(RefreshSeriesCommand message)
{ {
_eventAggregator.PublishEvent(new SeriesRefreshStartingEvent(message.Trigger == CommandTrigger.Manual)); _eventAggregator.PublishEvent(new SeriesRefreshStartingEvent(message.Trigger == CommandTrigger.Manual));
@ -151,7 +163,17 @@ namespace NzbDrone.Core.Tv
if (message.SeriesId.HasValue) if (message.SeriesId.HasValue)
{ {
var series = _seriesService.GetSeries(message.SeriesId.Value); 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 else
{ {
@ -168,20 +190,14 @@ namespace NzbDrone.Core.Tv
catch (Exception e) catch (Exception e)
{ {
_logger.Error(e, "Couldn't refresh info for {0}", series); _logger.Error(e, "Couldn't refresh info for {0}", series);
RescanSeries(series);
} }
} }
else else
{ {
try _logger.Info("Skipping refresh of series: {0}", series.Title);
{ RescanSeries(series);
_logger.Info("Skipping refresh of series: {0}", series.Title);
_diskScanService.Scan(series);
}
catch (Exception e)
{
_logger.Error(e, "Couldn't rescan series {0}", series);
}
} }
} }
} }