Priority/JobProvider tweaks
This commit is contained in:
parent
291e2c399e
commit
77c82df482
|
@ -98,6 +98,7 @@ namespace NzbDrone.Core.Test
|
||||||
|
|
||||||
firstRun.Should().BeTrue();
|
firstRun.Should().BeTrue();
|
||||||
secondRun.Should().BeTrue();
|
secondRun.Should().BeTrue();
|
||||||
|
JobProvider.Queue.Should().BeEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
@ -113,12 +114,13 @@ namespace NzbDrone.Core.Test
|
||||||
|
|
||||||
var timerProvider = mocker.Resolve<JobProvider>();
|
var timerProvider = mocker.Resolve<JobProvider>();
|
||||||
timerProvider.Initialize();
|
timerProvider.Initialize();
|
||||||
var firstRun = timerProvider.QueueJob(typeof(SlowJob), 1);
|
timerProvider.QueueJob(typeof(SlowJob), 1);
|
||||||
var secondRun = timerProvider.QueueJob(typeof(SlowJob), 2);
|
timerProvider.QueueJob(typeof(SlowJob), 2);
|
||||||
var third = timerProvider.QueueJob(typeof(SlowJob), 3);
|
timerProvider.QueueJob(typeof(SlowJob), 3);
|
||||||
|
|
||||||
|
|
||||||
Thread.Sleep(10000);
|
Thread.Sleep(10000);
|
||||||
|
JobProvider.Queue.Should().BeEmpty();
|
||||||
//Asserts are done in ExceptionVerification
|
//Asserts are done in ExceptionVerification
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,6 +145,7 @@ namespace NzbDrone.Core.Test
|
||||||
firstRun.Should().BeTrue();
|
firstRun.Should().BeTrue();
|
||||||
secondRun.Should().BeTrue();
|
secondRun.Should().BeTrue();
|
||||||
Thread.Sleep(2000);
|
Thread.Sleep(2000);
|
||||||
|
JobProvider.Queue.Should().BeEmpty();
|
||||||
ExceptionVerification.ExcpectedErrors(2);
|
ExceptionVerification.ExcpectedErrors(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,6 +209,7 @@ namespace NzbDrone.Core.Test
|
||||||
Thread.Sleep(5000);
|
Thread.Sleep(5000);
|
||||||
|
|
||||||
Assert.AreEqual(1, slowJob.ExexutionCount);
|
Assert.AreEqual(1, slowJob.ExexutionCount);
|
||||||
|
JobProvider.Queue.Should().BeEmpty();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -362,6 +366,7 @@ namespace NzbDrone.Core.Test
|
||||||
var settings = timerProvider.All();
|
var settings = timerProvider.All();
|
||||||
settings.Should().NotBeEmpty();
|
settings.Should().NotBeEmpty();
|
||||||
settings[0].LastExecution.Should().HaveYear(2000);
|
settings[0].LastExecution.Should().HaveYear(2000);
|
||||||
|
JobProvider.Queue.Should().BeEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
|
|
|
@ -21,7 +21,9 @@ namespace NzbDrone.Core.Providers.Jobs
|
||||||
private static readonly object ExecutionLock = new object();
|
private static readonly object ExecutionLock = new object();
|
||||||
private Thread _jobThread;
|
private Thread _jobThread;
|
||||||
private static bool _isRunning;
|
private static bool _isRunning;
|
||||||
private static readonly List<Tuple<Type, Int32>> Queue = new List<Tuple<Type, int>>();
|
public static readonly List<Tuple<Type, Int32>> Queue = new List<Tuple<Type, int>>();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private ProgressNotification _notification;
|
private ProgressNotification _notification;
|
||||||
|
|
||||||
|
@ -35,7 +37,6 @@ namespace NzbDrone.Core.Providers.Jobs
|
||||||
|
|
||||||
public JobProvider() { }
|
public JobProvider() { }
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a list of all registered jobs
|
/// Returns a list of all registered jobs
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -158,7 +159,7 @@ namespace NzbDrone.Core.Providers.Jobs
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
_jobThread = new Thread(starter) { Name = "JobQueueThread", Priority = ThreadPriority.BelowNormal };
|
_jobThread = new Thread(starter) { Name = "JobQueueThread" };
|
||||||
_jobThread.Start();
|
_jobThread.Start();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -176,45 +177,41 @@ namespace NzbDrone.Core.Providers.Jobs
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void ProcessQueue()
|
private void ProcessQueue()
|
||||||
{
|
{
|
||||||
Tuple<Type, int> job = null;
|
do
|
||||||
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
lock (Queue)
|
Tuple<Type, int> job = null;
|
||||||
|
|
||||||
|
try
|
||||||
{
|
{
|
||||||
if (Queue.Count != 0)
|
lock (Queue)
|
||||||
{
|
{
|
||||||
job = Queue[0];
|
if (Queue.Count != 0)
|
||||||
|
{
|
||||||
|
job = Queue.First();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (job != null)
|
||||||
|
{
|
||||||
|
Execute(job.Item1, job.Item2);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Logger.FatalException("An error has occurred while processing queued job.", e);
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (job != null)
|
||||||
|
{
|
||||||
|
Queue.Remove(job);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (job != null)
|
} while (Queue.Count != 0);
|
||||||
{
|
|
||||||
Execute(job.Item1, job.Item2);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
Logger.Trace("Finished processing jobs in the queue.");
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Logger.FatalException("An error has occurred while processing queued job.", e);
|
|
||||||
}
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
if (job != null)
|
|
||||||
{
|
|
||||||
Queue.Remove(job);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Try to find next job is last run found a job.
|
|
||||||
if (job != null)
|
|
||||||
{
|
|
||||||
ProcessQueue();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Logger.Trace("Finished processing jobs in the queue.");
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,11 +19,8 @@ namespace NzbDrone
|
||||||
Thread.CurrentThread.Name = "Host";
|
Thread.CurrentThread.Name = "Host";
|
||||||
|
|
||||||
Process currentProcess = Process.GetCurrentProcess();
|
Process currentProcess = Process.GetCurrentProcess();
|
||||||
if (currentProcess.PriorityClass < ProcessPriorityClass.Normal)
|
|
||||||
{
|
FixPriorities();
|
||||||
Logger.Info("Promoting process priority from {0} to {1}", currentProcess.PriorityClass, ProcessPriorityClass.Normal);
|
|
||||||
currentProcess.PriorityClass = ProcessPriorityClass.Normal;
|
|
||||||
}
|
|
||||||
|
|
||||||
currentProcess.EnableRaisingEvents = true;
|
currentProcess.EnableRaisingEvents = true;
|
||||||
currentProcess.Exited += ProgramExited;
|
currentProcess.Exited += ProgramExited;
|
||||||
|
@ -38,6 +35,8 @@ namespace NzbDrone
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
Attach();
|
Attach();
|
||||||
#endif
|
#endif
|
||||||
|
FixPriorities();
|
||||||
|
|
||||||
if (Environment.UserInteractive)
|
if (Environment.UserInteractive)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
|
@ -64,6 +63,25 @@ namespace NzbDrone
|
||||||
Console.ReadLine();
|
Console.ReadLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void FixPriorities()
|
||||||
|
{
|
||||||
|
Process currentProcess = Process.GetCurrentProcess();
|
||||||
|
if (currentProcess.PriorityClass < ProcessPriorityClass.Normal)
|
||||||
|
{
|
||||||
|
Logger.Info("Promoting process priority from {0} to {1}", currentProcess.PriorityClass,
|
||||||
|
ProcessPriorityClass.Normal);
|
||||||
|
currentProcess.PriorityClass = ProcessPriorityClass.Normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (IISController.IISProcess!=null && IISController.IISProcess.PriorityClass < ProcessPriorityClass.Normal)
|
||||||
|
{
|
||||||
|
Logger.Info("Promoting process priority from {0} to {1}", IISController.IISProcess.PriorityClass,
|
||||||
|
ProcessPriorityClass.Normal);
|
||||||
|
IISController.IISProcess.PriorityClass = ProcessPriorityClass.Normal;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
private static void Attach()
|
private static void Attach()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue