From 0d02b0538b02de574d2ba9f78a0ed0c8cb8b0e66 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Thu, 19 May 2011 23:25:39 -0700 Subject: [PATCH] fixed a concurrency issue with job provider. --- NzbDrone.Core.Test/JobProviderTest.cs | 25 +++++++++++++++++++++ NzbDrone.Core/Providers/Jobs/JobProvider.cs | 7 +++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/NzbDrone.Core.Test/JobProviderTest.cs b/NzbDrone.Core.Test/JobProviderTest.cs index 380eaa461..b160a0c3c 100644 --- a/NzbDrone.Core.Test/JobProviderTest.cs +++ b/NzbDrone.Core.Test/JobProviderTest.cs @@ -100,6 +100,29 @@ namespace NzbDrone.Core.Test } + [Test] + //This test will confirm that the concurrency checks are rest + //after execution so the job can successfully run. + public void no_concurent_jobs() + { + IEnumerable fakeJobs = new List { new SlowJob() }; + var mocker = new AutoMoqer(); + + mocker.SetConstant(MockLib.GetEmptyRepository()); + mocker.SetConstant(fakeJobs); + + var timerProvider = mocker.Resolve(); + timerProvider.Initialize(); + var firstRun = timerProvider.QueueJob(typeof(SlowJob),1); + var secondRun = timerProvider.QueueJob(typeof(SlowJob),2); + var third = timerProvider.QueueJob(typeof(SlowJob),3); + + + Thread.Sleep(10000); + + } + + [Test] //This test will confirm that the concurrency checks are rest //after execution so the job can successfully run. @@ -436,8 +459,10 @@ namespace NzbDrone.Core.Test public void Start(ProgressNotification notification, int targetId) { + Console.WriteLine("Starting Job"); Thread.Sleep(2000); ExexutionCount++; + Console.WriteLine("Finishing Job"); } } } \ No newline at end of file diff --git a/NzbDrone.Core/Providers/Jobs/JobProvider.cs b/NzbDrone.Core/Providers/Jobs/JobProvider.cs index 6551a2c62..56ad1ee12 100644 --- a/NzbDrone.Core/Providers/Jobs/JobProvider.cs +++ b/NzbDrone.Core/Providers/Jobs/JobProvider.cs @@ -106,7 +106,7 @@ namespace NzbDrone.Core.Providers.Jobs /// Type of the job that should be executed. /// The targetId could be any Id parameter eg. SeriesId. it will be passed to the job implementation /// to allow it to filter it's target of execution. - /// True if ran, false if skipped + /// True if queued, false if duplicate and was skipped /// Job is only added to the queue if same job with the same targetId doesn't already exist in the queue. public virtual bool QueueJob(Type jobType, int targetId = 0) { @@ -133,7 +133,7 @@ namespace NzbDrone.Core.Providers.Jobs Logger.Trace("Queue is already running. Ignoring request."); return true; } - + _isRunning = true; } if (_jobThread == null || !_jobThread.IsAlive) @@ -158,7 +158,8 @@ namespace NzbDrone.Core.Providers.Jobs } else { - Logger.Warn("Thread still active. Ignoring request."); + Logger.Warn("Execution lock has has fucked up. Thread still active. Ignoring request."); + return true; } return true;