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,23 +86,23 @@ 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,
|
||||||
{
|
TypeName = job.GetType().ToString(),
|
||||||
Enable = jobLocal.DefaultInterval > 0,
|
Name = jobLocal.Name,
|
||||||
TypeName = job.GetType().ToString(),
|
Interval = jobLocal.DefaultInterval,
|
||||||
Name = jobLocal.Name,
|
LastExecution = DateTime.Now
|
||||||
Interval = jobLocal.DefaultInterval,
|
};
|
||||||
LastExecution = DateTime.Now
|
|
||||||
};
|
|
||||||
|
|
||||||
SaveDefinition(settings);
|
if (currentJobs.Exists(c => c.TypeName == jobLocal.GetType().ToString()))
|
||||||
|
{
|
||||||
|
settings.Id = currentJobs.Single(c => c.TypeName == jobLocal.GetType().ToString()).Id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SaveDefinition(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
Loading…
Reference in New Issue