mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-16 11:37:58 +02:00
Fixed series refresh repeated too often if Sonarr is killed before Scheduled task finishes.
Fixes #735
This commit is contained in:
parent
408991e03c
commit
7991a3f1c3
@ -17,55 +17,9 @@ public class ShouldRefreshSeriesFixture : TestBase<ShouldRefreshSeries>
|
||||
public void Setup()
|
||||
{
|
||||
_series = Builder<Series>.CreateNew()
|
||||
.With(v => v.Status == SeriesStatusType.Continuing)
|
||||
.Build();
|
||||
}
|
||||
|
||||
private void GivenSeriesIsEnded()
|
||||
{
|
||||
_series.Status = SeriesStatusType.Ended;
|
||||
}
|
||||
|
||||
private void GivenSeriesLastRefreshedRecently()
|
||||
{
|
||||
_series.LastInfoSync = DateTime.UtcNow.AddDays(-1);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_series_is_continuing()
|
||||
{
|
||||
_series.Status = SeriesStatusType.Continuing;
|
||||
|
||||
Subject.ShouldRefresh(_series).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_series_last_refreshed_more_than_30_days_ago()
|
||||
{
|
||||
GivenSeriesIsEnded();
|
||||
_series.LastInfoSync = DateTime.UtcNow.AddDays(-100);
|
||||
|
||||
Subject.ShouldRefresh(_series).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_should_return_true_if_episode_aired_in_last_30_days()
|
||||
{
|
||||
Mocker.GetMock<IEpisodeService>()
|
||||
.Setup(s => s.GetEpisodeBySeries(_series.Id))
|
||||
.Returns(Builder<Episode>.CreateListOfSize(2)
|
||||
.TheFirst(1)
|
||||
.With(e => e.AirDateUtc = DateTime.Today.AddDays(-7))
|
||||
.TheLast(1)
|
||||
.With(e => e.AirDateUtc = DateTime.Today.AddDays(-100))
|
||||
.Build()
|
||||
.ToList());
|
||||
|
||||
Subject.ShouldRefresh(_series).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_should_return_false_when_recently_refreshed_ended_show_has_not_aired_for_30_days()
|
||||
{
|
||||
Mocker.GetMock<IEpisodeService>()
|
||||
.Setup(s => s.GetEpisodeBySeries(_series.Id))
|
||||
.Returns(Builder<Episode>.CreateListOfSize(2)
|
||||
@ -73,8 +27,102 @@ public void should_should_return_false_when_recently_refreshed_ended_show_has_no
|
||||
.With(e => e.AirDateUtc = DateTime.Today.AddDays(-100))
|
||||
.Build()
|
||||
.ToList());
|
||||
}
|
||||
|
||||
private void GivenSeriesIsEnded()
|
||||
{
|
||||
_series.Status = SeriesStatusType.Ended;
|
||||
}
|
||||
|
||||
private void GivenSeriesLastRefreshedMonthsAgo()
|
||||
{
|
||||
_series.LastInfoSync = DateTime.UtcNow.AddDays(-90);
|
||||
}
|
||||
|
||||
private void GivenSeriesLastRefreshedYesterday()
|
||||
{
|
||||
_series.LastInfoSync = DateTime.UtcNow.AddDays(-1);
|
||||
}
|
||||
|
||||
private void GivenSeriesLastRefreshedRecently()
|
||||
{
|
||||
_series.LastInfoSync = DateTime.UtcNow.AddHours(-1);
|
||||
}
|
||||
|
||||
private void GivenRecentlyAired()
|
||||
{
|
||||
Mocker.GetMock<IEpisodeService>()
|
||||
.Setup(s => s.GetEpisodeBySeries(_series.Id))
|
||||
.Returns(Builder<Episode>.CreateListOfSize(2)
|
||||
.TheFirst(1)
|
||||
.With(e => e.AirDateUtc = DateTime.Today.AddDays(-7))
|
||||
.TheLast(1)
|
||||
.With(e => e.AirDateUtc = DateTime.Today.AddDays(-100))
|
||||
.Build()
|
||||
.ToList());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_running_series_last_refreshed_more_than_6_hours_ago()
|
||||
{
|
||||
Subject.ShouldRefresh(_series).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_running_series_last_refreshed_less_than_6_hours_ago()
|
||||
{
|
||||
GivenSeriesLastRefreshedRecently();
|
||||
|
||||
Subject.ShouldRefresh(_series).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_if_ended_series_last_refreshed_yesterday()
|
||||
{
|
||||
GivenSeriesIsEnded();
|
||||
GivenSeriesLastRefreshedYesterday();
|
||||
|
||||
Subject.ShouldRefresh(_series).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_series_last_refreshed_more_than_30_days_ago()
|
||||
{
|
||||
GivenSeriesIsEnded();
|
||||
GivenSeriesLastRefreshedMonthsAgo();
|
||||
|
||||
Subject.ShouldRefresh(_series).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_true_if_episode_aired_in_last_30_days()
|
||||
{
|
||||
GivenSeriesIsEnded();
|
||||
GivenSeriesLastRefreshedYesterday();
|
||||
|
||||
GivenRecentlyAired();
|
||||
|
||||
Subject.ShouldRefresh(_series).Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_when_recently_refreshed_ended_show_has_not_aired_for_30_days()
|
||||
{
|
||||
GivenSeriesIsEnded();
|
||||
GivenSeriesLastRefreshedYesterday();
|
||||
|
||||
Subject.ShouldRefresh(_series).Should().BeFalse();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_return_false_when_recently_refreshed_ended_show_aired_in_last_30_days()
|
||||
{
|
||||
GivenSeriesIsEnded();
|
||||
GivenSeriesLastRefreshedRecently();
|
||||
|
||||
GivenRecentlyAired();
|
||||
|
||||
Subject.ShouldRefresh(_series).Should().BeFalse();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,18 +22,24 @@ public ShouldRefreshSeries(IEpisodeService episodeService, Logger logger)
|
||||
|
||||
public bool ShouldRefresh(Series series)
|
||||
{
|
||||
if (series.Status == SeriesStatusType.Continuing)
|
||||
{
|
||||
_logger.Trace("Series {0} is continuing, should refresh.", series.Title);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (series.LastInfoSync < DateTime.UtcNow.AddDays(-30))
|
||||
{
|
||||
_logger.Trace("Series {0} last updated more than 30 days ago, should refresh.", series.Title);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (series.LastInfoSync >= DateTime.UtcNow.AddHours(-6))
|
||||
{
|
||||
_logger.Trace("Series {0} last updated less than 6 hours ago, should not be refreshed.", series.Title);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (series.Status == SeriesStatusType.Continuing)
|
||||
{
|
||||
_logger.Trace("Series {0} is continuing, should refresh.", series.Title);
|
||||
return true;
|
||||
}
|
||||
|
||||
var lastEpisode = _episodeService.GetEpisodeBySeries(series.Id).OrderByDescending(e => e.AirDateUtc).FirstOrDefault();
|
||||
|
||||
if (lastEpisode != null && lastEpisode.AirDateUtc > DateTime.UtcNow.AddDays(-30))
|
||||
@ -42,7 +48,7 @@ public bool ShouldRefresh(Series series)
|
||||
return true;
|
||||
}
|
||||
|
||||
_logger.Trace("Series {0} should not be refreshed.", series.Title);
|
||||
_logger.Trace("Series {0} ended long ago, should not be refreshed.", series.Title);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user