mirror of https://github.com/lidarr/Lidarr
Merge branch 'kay.one' of github.com:NzbDrone/NzbDrone into markus
Conflicts: NzbDrone.Core.Test/ProviderTests/JobProviderTests/JobProviderFixture.cs
This commit is contained in:
commit
9a0fe35008
|
@ -25,7 +25,6 @@ namespace NzbDrone.Common
|
||||||
{
|
{
|
||||||
if (isInDebug || Debugger.IsAttached) return false;
|
if (isInDebug || Debugger.IsAttached) return false;
|
||||||
|
|
||||||
Console.WriteLine(processName);
|
|
||||||
if (processName.Contains("nunit")) return false;
|
if (processName.Contains("nunit")) return false;
|
||||||
if (processName.Contains("jetbrain")) return false;
|
if (processName.Contains("jetbrain")) return false;
|
||||||
if (processName.Contains("resharper")) return false;
|
if (processName.Contains("resharper")) return false;
|
||||||
|
|
|
@ -118,7 +118,7 @@ namespace NzbDrone.Common
|
||||||
private void OnOutputDataReceived(object s, DataReceivedEventArgs e)
|
private void OnOutputDataReceived(object s, DataReceivedEventArgs e)
|
||||||
{
|
{
|
||||||
if (e == null || String.IsNullOrWhiteSpace(e.Data) || e.Data.StartsWith("Request started:") ||
|
if (e == null || String.IsNullOrWhiteSpace(e.Data) || e.Data.StartsWith("Request started:") ||
|
||||||
e.Data.StartsWith("Request ended:") || e.Data == ("IncrementMessages called") || e.Data == "iisexpress" || e.Data == "nzbdrone")
|
e.Data.StartsWith("Request ended:") || e.Data == ("IncrementMessages called"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Console.WriteLine(e.Data);
|
Console.WriteLine(e.Data);
|
||||||
|
|
|
@ -4,10 +4,12 @@ using System.Linq;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
|
using FizzWare.NBuilder;
|
||||||
using FluentAssertions;
|
using FluentAssertions;
|
||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using NzbDrone.Core.Jobs;
|
using NzbDrone.Core.Jobs;
|
||||||
using NzbDrone.Core.Model;
|
using NzbDrone.Core.Model;
|
||||||
|
using NzbDrone.Core.Repository;
|
||||||
using NzbDrone.Core.Test.Framework;
|
using NzbDrone.Core.Test.Framework;
|
||||||
using NzbDrone.Test.Common;
|
using NzbDrone.Test.Common;
|
||||||
using NzbDrone.Test.Common.AutoMoq;
|
using NzbDrone.Test.Common.AutoMoq;
|
||||||
|
@ -282,6 +284,27 @@ namespace NzbDrone.Core.Test.ProviderTests.JobProviderTests
|
||||||
timers[0].Enable.Should().BeTrue();
|
timers[0].Enable.Should().BeTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void inti_should_removed_jobs_that_no_longer_exist()
|
||||||
|
{
|
||||||
|
IList<IJob> fakeJobs = new List<IJob> { fakeJob };
|
||||||
|
Mocker.SetConstant(fakeJobs);
|
||||||
|
|
||||||
|
WithRealDb();
|
||||||
|
var deletedJob = Builder<JobDefinition>.CreateNew().Build();
|
||||||
|
Db.Insert(deletedJob);
|
||||||
|
var jobProvider = Mocker.Resolve<JobProvider>();
|
||||||
|
|
||||||
|
//Act
|
||||||
|
jobProvider.Initialize();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
var registeredJobs = Db.Fetch<JobDefinition>();
|
||||||
|
registeredJobs.Should().HaveCount(1);
|
||||||
|
registeredJobs.Should().NotContain(c => c.Name == deletedJob.Name);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void jobs_with_zero_interval_are_registered_as_disabled()
|
public void jobs_with_zero_interval_are_registered_as_disabled()
|
||||||
{
|
{
|
||||||
|
@ -296,24 +319,6 @@ namespace NzbDrone.Core.Test.ProviderTests.JobProviderTests
|
||||||
jobProvider.All().First().Enable.Should().BeFalse();
|
jobProvider.All().First().Enable.Should().BeFalse();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
|
||||||
public void Get_Next_Execution_Time()
|
|
||||||
{
|
|
||||||
IList<IJob> BaseFakeJobs = new List<IJob> { fakeJob };
|
|
||||||
Mocker.SetConstant(BaseFakeJobs);
|
|
||||||
|
|
||||||
//Act
|
|
||||||
var jobProvider = Mocker.Resolve<JobProvider>();
|
|
||||||
jobProvider.Initialize();
|
|
||||||
jobProvider.QueueScheduled();
|
|
||||||
WaitForQueue();
|
|
||||||
|
|
||||||
//Assert
|
|
||||||
var next = jobProvider.NextScheduledRun(typeof(FakeJob));
|
|
||||||
jobProvider.All().Should().HaveCount(1);
|
|
||||||
jobProvider.All().First().LastExecution.Should().Be(next.AddMinutes(-fakeJob.DefaultInterval));
|
|
||||||
}
|
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void disabled_jobs_arent_run_by_scheduler()
|
public void disabled_jobs_arent_run_by_scheduler()
|
||||||
{
|
{
|
||||||
|
|
|
@ -64,40 +64,45 @@ namespace NzbDrone.Core.Jobs
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Returns a list of all registered jobs
|
|
||||||
/// </summary>
|
|
||||||
public virtual List<JobDefinition> All()
|
public virtual List<JobDefinition> All()
|
||||||
{
|
{
|
||||||
return _database.Fetch<JobDefinition>().ToList();
|
return _database.Fetch<JobDefinition>().ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Initializes jobs in the database using the IJob instances that are
|
|
||||||
/// registered using ninject
|
|
||||||
/// </summary>
|
|
||||||
public virtual void Initialize()
|
public virtual void Initialize()
|
||||||
{
|
{
|
||||||
logger.Debug("Initializing jobs. Count {0}", _jobs.Count());
|
var currentJobs = All();
|
||||||
var currentTimer = All();
|
logger.Debug("Initializing jobs. Available: {0} Existing:{1}", _jobs.Count(), currentJobs.Count);
|
||||||
|
|
||||||
foreach (var timer in _jobs)
|
foreach (var currentJob in currentJobs)
|
||||||
{
|
{
|
||||||
var timerProviderLocal = timer;
|
if (!_jobs.Any(c => c.Name == currentJob.Name))
|
||||||
if (!currentTimer.Exists(c => c.TypeName == timerProviderLocal.GetType().ToString()))
|
{
|
||||||
|
logger.Debug("Removing job from database '{0}'", currentJob.Name);
|
||||||
|
_database.Delete(currentJob);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var job in _jobs)
|
||||||
|
{
|
||||||
|
var jobLocal = job;
|
||||||
|
if (!currentJobs.Exists(c => c.TypeName == jobLocal.GetType().ToString()))
|
||||||
{
|
{
|
||||||
var settings = new JobDefinition
|
var settings = new JobDefinition
|
||||||
{
|
{
|
||||||
Enable = timerProviderLocal.DefaultInterval > 0,
|
Enable = jobLocal.DefaultInterval > 0,
|
||||||
TypeName = timer.GetType().ToString(),
|
TypeName = job.GetType().ToString(),
|
||||||
Name = timerProviderLocal.Name,
|
Name = jobLocal.Name,
|
||||||
Interval = timerProviderLocal.DefaultInterval,
|
Interval = jobLocal.DefaultInterval,
|
||||||
LastExecution = DateTime.Now
|
LastExecution = DateTime.Now
|
||||||
};
|
};
|
||||||
|
|
||||||
SaveDefinition(settings);
|
SaveDefinition(settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -141,17 +146,6 @@ namespace NzbDrone.Core.Jobs
|
||||||
logger.Trace("{0} Scheduled tasks have been added to the queue", pendingJobTypes.Count);
|
logger.Trace("{0} Scheduled tasks have been added to the queue", pendingJobTypes.Count);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Gets the next scheduled run time for a specific job
|
|
||||||
/// (Estimated due to schedule timer)
|
|
||||||
/// </summary>
|
|
||||||
/// <returns>DateTime of next scheduled job execution</returns>
|
|
||||||
public virtual DateTime NextScheduledRun(Type jobType)
|
|
||||||
{
|
|
||||||
var job = All().Where(t => t.TypeName == jobType.ToString()).Single();
|
|
||||||
return job.LastExecution.AddMinutes(job.Interval);
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual void QueueJob(Type jobType, int targetId = 0, int secondaryTargetId = 0)
|
public virtual void QueueJob(Type jobType, int targetId = 0, int secondaryTargetId = 0)
|
||||||
{
|
{
|
||||||
var queueItem = new JobQueueItem
|
var queueItem = new JobQueueItem
|
||||||
|
|
|
@ -64,17 +64,6 @@ namespace NzbDrone
|
||||||
Logger.ErrorException("Failed to open URL in default browser.", e);
|
Logger.ErrorException("Failed to open URL in default browser.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
_webClient.DownloadString(_iisProvider.AppUrl);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Logger.ErrorException("Failed to load home page.", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_monitoringProvider.Start();
|
_monitoringProvider.Start();
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,7 +94,13 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="app.config" />
|
<None Include="app.config" />
|
||||||
|
<None Include="ServiceInstall.bat">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
<None Include="packages.config" />
|
<None Include="packages.config" />
|
||||||
|
<None Include="ServiceUninstall.bat">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Include="NzbDrone.ico" />
|
<Content Include="NzbDrone.ico" />
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
@ECHO OFF
|
||||||
|
nzbdrone.exe /i
|
||||||
|
net start nzbdrone
|
||||||
|
pause
|
|
@ -0,0 +1,4 @@
|
||||||
|
@ECHO OFF
|
||||||
|
net stop nzbdrone
|
||||||
|
nzbdrone.exe /u
|
||||||
|
pause
|
Loading…
Reference in New Issue