mirror of https://github.com/Radarr/Radarr
Priority/JobProvider tweaks
This commit is contained in:
parent
291e2c399e
commit
77c82df482
|
@ -98,6 +98,7 @@ namespace NzbDrone.Core.Test
|
|||
|
||||
firstRun.Should().BeTrue();
|
||||
secondRun.Should().BeTrue();
|
||||
JobProvider.Queue.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
@ -113,12 +114,13 @@ namespace NzbDrone.Core.Test
|
|||
|
||||
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);
|
||||
timerProvider.QueueJob(typeof(SlowJob), 1);
|
||||
timerProvider.QueueJob(typeof(SlowJob), 2);
|
||||
timerProvider.QueueJob(typeof(SlowJob), 3);
|
||||
|
||||
|
||||
Thread.Sleep(10000);
|
||||
JobProvider.Queue.Should().BeEmpty();
|
||||
//Asserts are done in ExceptionVerification
|
||||
}
|
||||
|
||||
|
@ -143,6 +145,7 @@ namespace NzbDrone.Core.Test
|
|||
firstRun.Should().BeTrue();
|
||||
secondRun.Should().BeTrue();
|
||||
Thread.Sleep(2000);
|
||||
JobProvider.Queue.Should().BeEmpty();
|
||||
ExceptionVerification.ExcpectedErrors(2);
|
||||
}
|
||||
|
||||
|
@ -206,6 +209,7 @@ namespace NzbDrone.Core.Test
|
|||
Thread.Sleep(5000);
|
||||
|
||||
Assert.AreEqual(1, slowJob.ExexutionCount);
|
||||
JobProvider.Queue.Should().BeEmpty();
|
||||
|
||||
}
|
||||
|
||||
|
@ -362,6 +366,7 @@ namespace NzbDrone.Core.Test
|
|||
var settings = timerProvider.All();
|
||||
settings.Should().NotBeEmpty();
|
||||
settings[0].LastExecution.Should().HaveYear(2000);
|
||||
JobProvider.Queue.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
|
|
@ -21,7 +21,9 @@ namespace NzbDrone.Core.Providers.Jobs
|
|||
private static readonly object ExecutionLock = new object();
|
||||
private Thread _jobThread;
|
||||
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;
|
||||
|
||||
|
@ -35,7 +37,6 @@ namespace NzbDrone.Core.Providers.Jobs
|
|||
|
||||
public JobProvider() { }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Returns a list of all registered jobs
|
||||
/// </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();
|
||||
|
||||
}
|
||||
|
@ -176,45 +177,41 @@ namespace NzbDrone.Core.Providers.Jobs
|
|||
/// </summary>
|
||||
private void ProcessQueue()
|
||||
{
|
||||
Tuple<Type, int> job = null;
|
||||
|
||||
try
|
||||
do
|
||||
{
|
||||
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)
|
||||
{
|
||||
Execute(job.Item1, job.Item2);
|
||||
}
|
||||
} while (Queue.Count != 0);
|
||||
|
||||
}
|
||||
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.");
|
||||
}
|
||||
Logger.Trace("Finished processing jobs in the queue.");
|
||||
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -19,11 +19,8 @@ namespace NzbDrone
|
|||
Thread.CurrentThread.Name = "Host";
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
FixPriorities();
|
||||
|
||||
currentProcess.EnableRaisingEvents = true;
|
||||
currentProcess.Exited += ProgramExited;
|
||||
|
@ -38,6 +35,8 @@ namespace NzbDrone
|
|||
#if DEBUG
|
||||
Attach();
|
||||
#endif
|
||||
FixPriorities();
|
||||
|
||||
if (Environment.UserInteractive)
|
||||
{
|
||||
try
|
||||
|
@ -64,6 +63,25 @@ namespace NzbDrone
|
|||
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
|
||||
private static void Attach()
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue