mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-04 10:02:40 +01:00
fixed jobs running all the time.
This commit is contained in:
parent
ba68dd9386
commit
77eedf448e
@ -1,8 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NzbDrone.Core.Tv;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
|
||||
namespace NzbDrone.Api.Episodes
|
||||
{
|
||||
|
@ -41,13 +41,13 @@ public void Init_should_add_defintaions()
|
||||
Subject.Init();
|
||||
|
||||
Storage.All().Should().HaveCount(1);
|
||||
Storage.All().ToList()[0].Interval.Should().Be((Int32)_fakeJob.DefaultInterval.TotalMinutes);
|
||||
Storage.All().ToList()[0].Name.Should().Be(_fakeJob.Name);
|
||||
Storage.All().ToList()[0].TypeName.Should().Be(_fakeJob.GetType().ToString());
|
||||
Storage.All().ToList()[0].LastExecution.Should().HaveYear(DateTime.Now.Year);
|
||||
Storage.All().ToList()[0].LastExecution.Should().HaveMonth(DateTime.Now.Month);
|
||||
Storage.All().ToList()[0].LastExecution.Should().HaveDay(DateTime.Today.Day);
|
||||
Storage.All().ToList()[0].Enable.Should().BeTrue();
|
||||
StoredModel.Interval.Should().Be((Int32)_fakeJob.DefaultInterval.TotalMinutes);
|
||||
StoredModel.Name.Should().Be(_fakeJob.Name);
|
||||
StoredModel.TypeName.Should().Be(_fakeJob.GetType().ToString());
|
||||
StoredModel.LastExecution.Should().HaveYear(DateTime.Now.Year);
|
||||
StoredModel.LastExecution.Should().HaveMonth(DateTime.Now.Month);
|
||||
StoredModel.LastExecution.Should().HaveDay(DateTime.Today.Day);
|
||||
StoredModel.Enable.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -65,9 +65,8 @@ public void inti_should_removed_jobs_that_no_longer_exist()
|
||||
Db.Insert(deletedJob);
|
||||
Subject.Init();
|
||||
|
||||
var registeredJobs = Storage.All();
|
||||
registeredJobs.Should().HaveCount(1);
|
||||
registeredJobs.Should().NotContain(c => c.TypeName == deletedJob.TypeName);
|
||||
AllStoredModels.Should().HaveCount(1);
|
||||
AllStoredModels.Should().NotContain(c => c.TypeName == deletedJob.TypeName);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -88,10 +87,8 @@ public void inti_should_removed_jobs_that_no_longer_exist_even_with_same_name()
|
||||
Subject.Init();
|
||||
|
||||
|
||||
|
||||
var registeredJobs = Storage.All();
|
||||
registeredJobs.Should().HaveCount(1);
|
||||
registeredJobs.Should().NotContain(c => c.TypeName == deletedJob.TypeName);
|
||||
AllStoredModels.Should().HaveCount(1);
|
||||
AllStoredModels.Should().NotContain(c => c.TypeName == deletedJob.TypeName);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -118,15 +115,13 @@ public void init_should_update_existing_job()
|
||||
Subject.Init();
|
||||
|
||||
|
||||
var registeredJobs = Storage.All();
|
||||
registeredJobs.Should().HaveCount(1);
|
||||
registeredJobs.First().TypeName.Should().Be(newJob.GetType().FullName);
|
||||
registeredJobs.First().Name.Should().Be(newJob.Name);
|
||||
registeredJobs.First().Interval.Should().Be((int)newJob.DefaultInterval.TotalMinutes);
|
||||
|
||||
registeredJobs.First().Enable.Should().Be(true);
|
||||
registeredJobs.First().Success.Should().Be(oldJob.Success);
|
||||
registeredJobs.First().LastExecution.Should().Be(oldJob.LastExecution);
|
||||
AllStoredModels.Should().HaveCount(1);
|
||||
StoredModel.TypeName.Should().Be(newJob.GetType().FullName);
|
||||
StoredModel.Name.Should().Be(newJob.Name);
|
||||
StoredModel.Interval.Should().Be((int)newJob.DefaultInterval.TotalMinutes);
|
||||
StoredModel.Enable.Should().Be(true);
|
||||
StoredModel.Success.Should().Be(oldJob.Success);
|
||||
StoredModel.LastExecution.Should().Be(oldJob.LastExecution);
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -142,6 +137,44 @@ public void jobs_with_zero_interval_are_registered_as_disabled()
|
||||
Storage.All().First().Enable.Should().BeFalse();
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void pending_job_should_get_jobs_that_have_matured()
|
||||
{
|
||||
var oldJob = Builder<JobDefinition>.CreateNew()
|
||||
.With(c => c.Id = 0)
|
||||
.With(c => c.Interval = 1)
|
||||
.With(c => c.Enable = true)
|
||||
.With(c => c.Success = true)
|
||||
.With(c => c.LastExecution = DateTime.Now.AddMinutes(-5))
|
||||
.Build();
|
||||
|
||||
|
||||
Storage.Insert(oldJob);
|
||||
|
||||
|
||||
Subject.GetPendingJobs().Should().HaveCount(1);
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public void pending_job_should_not_get_jobs_that_havent_matured()
|
||||
{
|
||||
var recent = Builder<JobDefinition>.CreateNew()
|
||||
.With(c => c.Id = 0)
|
||||
.With(c => c.Interval = 60)
|
||||
.With(c => c.Enable = true)
|
||||
.With(c => c.Success = true)
|
||||
.With(c => c.LastExecution = DateTime.Now.AddMinutes(-5))
|
||||
.Build();
|
||||
|
||||
|
||||
Storage.Insert(recent);
|
||||
|
||||
|
||||
Subject.GetPendingJobs().Should().BeEmpty();
|
||||
}
|
||||
|
||||
/* [Test]
|
||||
public void disabled_jobs_arent_run_by_scheduler()
|
||||
{
|
||||
|
@ -75,6 +75,9 @@ public void none_unique_season_episode_number()
|
||||
result.GroupBy(e => e.SeasonNumber.ToString("000") + e.EpisodeNumber.ToString("000"))
|
||||
.Max(e => e.Count()).Should().Be(1);
|
||||
|
||||
|
||||
result.Select(c => c.TvDbEpisodeId).Should().OnlyHaveUniqueItems();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -33,7 +33,7 @@ public JobDefinition GetDefinition(Type type)
|
||||
|
||||
public IList<JobDefinition> GetPendingJobs()
|
||||
{
|
||||
return Queryable.Where(c => c.Enable && c.LastExecution < DateTime.UtcNow.AddMinutes(c.Interval)).ToList();
|
||||
return Queryable.Where(c => c.Enable && c.LastExecution < DateTime.Now.AddMinutes(-c.Interval)).ToList();
|
||||
}
|
||||
|
||||
public void Init()
|
||||
|
@ -192,6 +192,8 @@ public void RefreshEpisodeInfo(Series series)
|
||||
logger.Trace("Updating info for [{0}] - S{1:00}E{2:00}", series.Title, episode.SeasonNumber, episode.EpisodeNumber);
|
||||
|
||||
//first check using tvdbId, this should cover cases when and episode number in a season is changed
|
||||
|
||||
var episodes = seriesEpisodes.Where(e => e.TvDbEpisodeId == episode.TvDbEpisodeId).ToList();
|
||||
var episodeToUpdate = seriesEpisodes.SingleOrDefault(e => e.TvDbEpisodeId == episode.TvDbEpisodeId);
|
||||
|
||||
//not found, try using season/episode number
|
||||
|
Loading…
Reference in New Issue
Block a user