JobProvider.Initialize will now update existing jobs.

pull/4/head
Mark McDowall 13 years ago
parent ac5296e0ab
commit f56bf62991

@ -326,6 +326,33 @@ namespace NzbDrone.Core.Test.ProviderTests.JobProviderTests
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]
public void jobs_with_zero_interval_are_registered_as_disabled()
{

@ -86,23 +86,23 @@ namespace NzbDrone.Core.Jobs
foreach (var job in _jobs)
{
var jobLocal = job;
if (!currentJobs.Exists(c => c.TypeName == jobLocal.GetType().ToString()))
var settings = new JobDefinition
{
Enable = jobLocal.DefaultInterval > 0,
TypeName = job.GetType().ToString(),
Name = jobLocal.Name,
Interval = jobLocal.DefaultInterval,
LastExecution = DateTime.Now
};
if (currentJobs.Exists(c => c.TypeName == jobLocal.GetType().ToString()))
{
var settings = new JobDefinition
{
Enable = jobLocal.DefaultInterval > 0,
TypeName = job.GetType().ToString(),
Name = jobLocal.Name,
Interval = jobLocal.DefaultInterval,
LastExecution = DateTime.Now
};
SaveDefinition(settings);
settings.Id = currentJobs.Single(c => c.TypeName == jobLocal.GetType().ToString()).Id;
}
}
SaveDefinition(settings);
}
}
/// <summary>

Loading…
Cancel
Save