mirror of https://github.com/Radarr/Radarr
Added NextScheduledRun to get the next scheduled run for a job, with a test.
This commit is contained in:
parent
d4c9e5d12f
commit
fdd6e37b24
|
@ -15,7 +15,6 @@ namespace NzbDrone.Core.Test
|
|||
[Test]
|
||||
public void Run_Jobs_Updates_Last_Execution()
|
||||
{
|
||||
|
||||
IEnumerable<IJob> fakeTimers = new List<IJob> { 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<IJob> fakeTimers = new List<IJob> { new FakeJob() };
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
mocker.SetConstant(MockLib.GetEmptyRepository());
|
||||
mocker.SetConstant(fakeTimers);
|
||||
|
||||
//Act
|
||||
var timerProvider = mocker.Resolve<JobProvider>();
|
||||
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
|
||||
|
|
|
@ -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
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the next scheduled run time for the job
|
||||
/// (Estimated due to schedule timer)
|
||||
/// </summary>
|
||||
/// <returns>DateTime of next scheduled job</returns>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue