diff --git a/NzbDrone.Core.Test/ProviderTests/JobProviderTests/JobProviderFixture.cs b/NzbDrone.Core.Test/ProviderTests/JobProviderTests/JobProviderFixture.cs index 82b2fe868..2094579bb 100644 --- a/NzbDrone.Core.Test/ProviderTests/JobProviderTests/JobProviderFixture.cs +++ b/NzbDrone.Core.Test/ProviderTests/JobProviderTests/JobProviderFixture.cs @@ -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 fakeJobs = new List { fakeJob }; + Mocker.SetConstant(fakeJobs); + + WithRealDb(); + var initialFakeJob = Builder.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(); + + //Act + jobProvider.Initialize(); + + //Assert + var registeredJobs = Db.Fetch(); + 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() { diff --git a/NzbDrone.Core/Jobs/JobProvider.cs b/NzbDrone.Core/Jobs/JobProvider.cs index 4a8e28e0b..6507f0120 100644 --- a/NzbDrone.Core/Jobs/JobProvider.cs +++ b/NzbDrone.Core/Jobs/JobProvider.cs @@ -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); + } } ///