From fdd6e37b246b494ec6077706ef6cd45eaa6b6075 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Mon, 16 May 2011 21:01:01 -0700 Subject: [PATCH] Added NextScheduledRun to get the next scheduled run for a job, with a test. --- NzbDrone.Core.Test/JobProviderTest.cs | 24 +++++++++++++++----- NzbDrone.Core/Providers/Jobs/JobProvider.cs | 14 +++++++++++- NzbDrone.Web/Controllers/SharedController.cs | 3 +-- NzbDrone.sln | 2 -- 4 files changed, 32 insertions(+), 11 deletions(-) diff --git a/NzbDrone.Core.Test/JobProviderTest.cs b/NzbDrone.Core.Test/JobProviderTest.cs index ed4eb960e..6c13ed0c8 100644 --- a/NzbDrone.Core.Test/JobProviderTest.cs +++ b/NzbDrone.Core.Test/JobProviderTest.cs @@ -15,7 +15,6 @@ namespace NzbDrone.Core.Test [Test] public void Run_Jobs_Updates_Last_Execution() { - IEnumerable fakeTimers = new List { new FakeJob() }; var mocker = new AutoMoqer(); @@ -99,7 +98,6 @@ namespace NzbDrone.Core.Test Assert.IsTrue(secondRun); } - [Test] //This test will confirm that the concurrency checks are rest //after execution so the job can successfully run. @@ -122,7 +120,6 @@ namespace NzbDrone.Core.Test } - [Test] //This test will confirm that the concurrency checks are rest //after execution so the job can successfully run. @@ -144,7 +141,6 @@ namespace NzbDrone.Core.Test Assert.IsTrue(secondRun); } - [Test] //This test will confirm that the concurrency checks are rest //after execution so the job can successfully run. @@ -234,8 +230,6 @@ namespace NzbDrone.Core.Test Assert.IsTrue(timers[0].Enable); } - - [Test] public void Init_Timers_sets_interval_0_to_disabled() { @@ -267,8 +261,26 @@ namespace NzbDrone.Core.Test Assert.IsFalse(timers[0].Enable); } + [Test] + public void Get_Next_Execution_Time() + { + IEnumerable fakeTimers = new List { new FakeJob() }; + var mocker = new AutoMoqer(); + mocker.SetConstant(MockLib.GetEmptyRepository()); + mocker.SetConstant(fakeTimers); + + //Act + var timerProvider = mocker.Resolve(); + timerProvider.Initialize(); + timerProvider.RunScheduled(); + var next = timerProvider.NextScheduledRun(typeof(FakeJob)); + //Assert + var settings = timerProvider.All(); + Assert.IsNotEmpty(settings); + Assert.AreEqual(next, settings[0].LastExecution.AddMinutes(15)); + } } public class FakeJob : IJob diff --git a/NzbDrone.Core/Providers/Jobs/JobProvider.cs b/NzbDrone.Core/Providers/Jobs/JobProvider.cs index 6e8e8aea8..9f962ef43 100644 --- a/NzbDrone.Core/Providers/Jobs/JobProvider.cs +++ b/NzbDrone.Core/Providers/Jobs/JobProvider.cs @@ -78,7 +78,6 @@ namespace NzbDrone.Core.Providers.Jobs try { - var pendingJobs = All().Where( t => t.Enable && (DateTime.Now - t.LastExecution) > TimeSpan.FromMinutes(t.Interval) @@ -218,6 +217,19 @@ namespace NzbDrone.Core.Providers.Jobs } } + /// + /// Gets the next scheduled run time for the job + /// (Estimated due to schedule timer) + /// + /// DateTime of next scheduled job + public virtual DateTime NextScheduledRun(Type jobType) + { + var job = All().Where(t => t.TypeName == jobType.ToString()).FirstOrDefault(); + + if (job == null) + return DateTime.Now; + return job.LastExecution.AddMinutes(job.Interval); + } } } \ No newline at end of file diff --git a/NzbDrone.Web/Controllers/SharedController.cs b/NzbDrone.Web/Controllers/SharedController.cs index ac6fab6bf..38181f2f4 100644 --- a/NzbDrone.Web/Controllers/SharedController.cs +++ b/NzbDrone.Web/Controllers/SharedController.cs @@ -22,8 +22,7 @@ namespace NzbDrone.Web.Controllers [ChildActionOnly] public ActionResult Footer() { - ViewData["RssTimer"] = DateTime.Now.ToString("yyyyMMddHHmmss"); - //ViewData["RssTimer"] = DateTime.Now.AddMinutes(61).AddSeconds(10).ToString("yyyyMMddHHmmss"); + ViewData["RssTimer"] = _jobProvider.NextScheduledRun(typeof(RssSyncJob)).ToString("yyyyMMddHHmmss"); return PartialView(); } } diff --git a/NzbDrone.sln b/NzbDrone.sln index 16b90b117..0b93d492d 100644 --- a/NzbDrone.sln +++ b/NzbDrone.sln @@ -27,7 +27,6 @@ Global GlobalSection(ProjectConfigurationPlatforms) = postSolution {D12F7F2F-8A3C-415F-88FA-6DD061A84869}.Debug|Any CPU.ActiveCfg = Debug|x86 {D12F7F2F-8A3C-415F-88FA-6DD061A84869}.Debug|Mixed Platforms.ActiveCfg = Debug|x86 - {D12F7F2F-8A3C-415F-88FA-6DD061A84869}.Debug|Mixed Platforms.Build.0 = Debug|x86 {D12F7F2F-8A3C-415F-88FA-6DD061A84869}.Debug|x64.ActiveCfg = Debug|x86 {D12F7F2F-8A3C-415F-88FA-6DD061A84869}.Debug|x86.ActiveCfg = Debug|x86 {D12F7F2F-8A3C-415F-88FA-6DD061A84869}.Debug|x86.Build.0 = Debug|x86 @@ -69,7 +68,6 @@ Global {193ADD3B-792B-4173-8E4C-5A3F8F0237F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {193ADD3B-792B-4173-8E4C-5A3F8F0237F0}.Debug|Any CPU.Build.0 = Debug|Any CPU {193ADD3B-792B-4173-8E4C-5A3F8F0237F0}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU - {193ADD3B-792B-4173-8E4C-5A3F8F0237F0}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU {193ADD3B-792B-4173-8E4C-5A3F8F0237F0}.Debug|x64.ActiveCfg = Debug|Any CPU {193ADD3B-792B-4173-8E4C-5A3F8F0237F0}.Debug|x86.ActiveCfg = Debug|Any CPU {193ADD3B-792B-4173-8E4C-5A3F8F0237F0}.Debug|x86.Build.0 = Debug|Any CPU