fixed a concurrency issue with job provider.

pull/4/head
kay.one 14 years ago
parent 8fca3c3419
commit 0d02b0538b

@ -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<IJob> fakeJobs = new List<IJob> { new SlowJob() };
var mocker = new AutoMoqer();
mocker.SetConstant(MockLib.GetEmptyRepository());
mocker.SetConstant(fakeJobs);
var timerProvider = mocker.Resolve<JobProvider>();
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");
}
}
}

@ -106,7 +106,7 @@ namespace NzbDrone.Core.Providers.Jobs
/// <param name="jobType">Type of the job that should be executed.</param>
/// <param name="targetId">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.</param>
/// <returns>True if ran, false if skipped</returns>
/// <returns>True if queued, false if duplicate and was skipped</returns>
/// <remarks>Job is only added to the queue if same job with the same targetId doesn't already exist in the queue.</remarks>
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;

Loading…
Cancel
Save