mirror of https://github.com/Radarr/Radarr
JobProvider.Initialize will now update existing jobs.
This commit is contained in:
parent
ac5296e0ab
commit
f56bf62991
|
@ -326,6 +326,33 @@ namespace NzbDrone.Core.Test.ProviderTests.JobProviderTests
|
||||||
registeredJobs.Should().NotContain(c => c.TypeName == deletedJob.TypeName);
|
registeredJobs.Should().NotContain(c => c.TypeName == deletedJob.TypeName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void init_should_update_existing_job()
|
||||||
|
{
|
||||||
|
IList<IJob> fakeJobs = new List<IJob> { fakeJob };
|
||||||
|
Mocker.SetConstant(fakeJobs);
|
||||||
|
|
||||||
|
WithRealDb();
|
||||||
|
var initialFakeJob = Builder<JobDefinition>.CreateNew()
|
||||||
|
.With(c => c.Name = fakeJob.Name)
|
||||||
|
.With(c => c.TypeName = fakeJob.GetType().ToString())
|
||||||
|
.With(c => c.Interval = 60)
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
var id = Convert.ToInt32(Db.Insert(initialFakeJob));
|
||||||
|
|
||||||
|
var jobProvider = Mocker.Resolve<JobProvider>();
|
||||||
|
|
||||||
|
//Act
|
||||||
|
jobProvider.Initialize();
|
||||||
|
|
||||||
|
//Assert
|
||||||
|
var registeredJobs = Db.Fetch<JobDefinition>();
|
||||||
|
registeredJobs.Should().HaveCount(1);
|
||||||
|
registeredJobs.First().Interval.Should().Be(fakeJob.DefaultInterval);
|
||||||
|
registeredJobs.First().Id.Should().Be(id);
|
||||||
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
public void jobs_with_zero_interval_are_registered_as_disabled()
|
public void jobs_with_zero_interval_are_registered_as_disabled()
|
||||||
{
|
{
|
||||||
|
|
|
@ -86,8 +86,7 @@ namespace NzbDrone.Core.Jobs
|
||||||
foreach (var job in _jobs)
|
foreach (var job in _jobs)
|
||||||
{
|
{
|
||||||
var jobLocal = job;
|
var jobLocal = job;
|
||||||
if (!currentJobs.Exists(c => c.TypeName == jobLocal.GetType().ToString()))
|
|
||||||
{
|
|
||||||
var settings = new JobDefinition
|
var settings = new JobDefinition
|
||||||
{
|
{
|
||||||
Enable = jobLocal.DefaultInterval > 0,
|
Enable = jobLocal.DefaultInterval > 0,
|
||||||
|
@ -97,14 +96,15 @@ namespace NzbDrone.Core.Jobs
|
||||||
LastExecution = DateTime.Now
|
LastExecution = DateTime.Now
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (currentJobs.Exists(c => c.TypeName == jobLocal.GetType().ToString()))
|
||||||
|
{
|
||||||
|
settings.Id = currentJobs.Single(c => c.TypeName == jobLocal.GetType().ToString()).Id;
|
||||||
|
}
|
||||||
|
|
||||||
SaveDefinition(settings);
|
SaveDefinition(settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds/Updates definitions for a job
|
/// Adds/Updates definitions for a job
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
Loading…
Reference in New Issue