mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-10 11:10:40 +02:00
Removed all static state tracking from job provider.
This commit is contained in:
parent
c23e736cc6
commit
6828f099bc
@ -84,5 +84,14 @@ public void quality_profile_initialized()
|
||||
{
|
||||
CentralDispatch.NinjectKernel.Get<QualityProvider>().All().Should().HaveCount(2);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void JobProvider_should_be_singletone()
|
||||
{
|
||||
var first = CentralDispatch.NinjectKernel.Get<JobProvider>();
|
||||
var second = CentralDispatch.NinjectKernel.Get<JobProvider>();
|
||||
|
||||
first.Should().BeSameAs(second);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ public virtual void Setup()
|
||||
[TearDown]
|
||||
public void TearDown()
|
||||
{
|
||||
JobProvider.Queue.Clear();
|
||||
ExceptionVerification.AssertNoUnexcpectedLogs();
|
||||
}
|
||||
|
||||
|
@ -17,13 +17,6 @@ namespace NzbDrone.Core.Test.ProviderTests
|
||||
// ReSharper disable InconsistentNaming
|
||||
public class JobProviderTest : TestBase
|
||||
{
|
||||
[TestFixtureSetUp]
|
||||
public override void Setup()
|
||||
{
|
||||
base.Setup();
|
||||
JobProvider.Queue.Clear();
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Run_Jobs_Updates_Last_Execution()
|
||||
{
|
||||
@ -100,13 +93,13 @@ public void can_run_async_job_again()
|
||||
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
||||
mocker.SetConstant(fakeJobs);
|
||||
|
||||
var timerProvider = mocker.Resolve<JobProvider>();
|
||||
timerProvider.Initialize();
|
||||
timerProvider.QueueJob(typeof(FakeJob));
|
||||
var jobProvider = mocker.Resolve<JobProvider>();
|
||||
jobProvider.Initialize();
|
||||
jobProvider.QueueJob(typeof(FakeJob));
|
||||
Thread.Sleep(1000);
|
||||
timerProvider.QueueJob(typeof(FakeJob));
|
||||
jobProvider.QueueJob(typeof(FakeJob));
|
||||
Thread.Sleep(2000);
|
||||
JobProvider.Queue.Should().BeEmpty();
|
||||
jobProvider.Queue.Should().BeEmpty();
|
||||
fakeJob.ExecutionCount.Should().Be(2);
|
||||
}
|
||||
|
||||
@ -119,15 +112,15 @@ public void no_concurent_jobs()
|
||||
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
||||
mocker.SetConstant(fakeJobs);
|
||||
|
||||
var timerProvider = mocker.Resolve<JobProvider>();
|
||||
timerProvider.Initialize();
|
||||
timerProvider.QueueJob(typeof(SlowJob), 1);
|
||||
timerProvider.QueueJob(typeof(SlowJob), 2);
|
||||
timerProvider.QueueJob(typeof(SlowJob), 3);
|
||||
var jobProvider = mocker.Resolve<JobProvider>();
|
||||
jobProvider.Initialize();
|
||||
jobProvider.QueueJob(typeof(SlowJob), 1);
|
||||
jobProvider.QueueJob(typeof(SlowJob), 2);
|
||||
jobProvider.QueueJob(typeof(SlowJob), 3);
|
||||
|
||||
|
||||
Thread.Sleep(5000);
|
||||
JobProvider.Queue.Should().BeEmpty();
|
||||
jobProvider.Queue.Should().BeEmpty();
|
||||
//Asserts are done in ExceptionVerification
|
||||
}
|
||||
|
||||
@ -144,15 +137,15 @@ public void can_run_broken_async_job_again()
|
||||
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
||||
mocker.SetConstant(fakeJobs);
|
||||
|
||||
var timerProvider = mocker.Resolve<JobProvider>();
|
||||
timerProvider.Initialize();
|
||||
timerProvider.QueueJob(typeof(BrokenJob));
|
||||
var jobProvider = mocker.Resolve<JobProvider>();
|
||||
jobProvider.Initialize();
|
||||
jobProvider.QueueJob(typeof(BrokenJob));
|
||||
Thread.Sleep(2000);
|
||||
timerProvider.QueueJob(typeof(BrokenJob));
|
||||
jobProvider.QueueJob(typeof(BrokenJob));
|
||||
|
||||
|
||||
Thread.Sleep(2000);
|
||||
JobProvider.Queue.Should().BeEmpty();
|
||||
jobProvider.Queue.Should().BeEmpty();
|
||||
brokenJob.ExecutionCount.Should().Be(2);
|
||||
ExceptionVerification.ExcpectedErrors(2);
|
||||
}
|
||||
@ -201,11 +194,11 @@ public void can_queue_jobs_at_the_same_time()
|
||||
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
||||
mocker.SetConstant(fakeJobs);
|
||||
|
||||
var timerProvider = mocker.Resolve<JobProvider>();
|
||||
timerProvider.Initialize();
|
||||
var jobProvider = mocker.Resolve<JobProvider>();
|
||||
jobProvider.Initialize();
|
||||
|
||||
var thread1 = new Thread(() => timerProvider.QueueJob(typeof(SlowJob)));
|
||||
var thread2 = new Thread(() => timerProvider.QueueJob(typeof(SlowJob)));
|
||||
var thread1 = new Thread(() => jobProvider.QueueJob(typeof(SlowJob)));
|
||||
var thread2 = new Thread(() => jobProvider.QueueJob(typeof(SlowJob)));
|
||||
|
||||
thread1.Start();
|
||||
thread2.Start();
|
||||
@ -216,7 +209,7 @@ public void can_queue_jobs_at_the_same_time()
|
||||
Thread.Sleep(5000);
|
||||
|
||||
Assert.AreEqual(1, slowJob.ExecutionCount);
|
||||
JobProvider.Queue.Should().BeEmpty();
|
||||
jobProvider.Queue.Should().BeEmpty();
|
||||
|
||||
}
|
||||
|
||||
@ -364,16 +357,16 @@ public void SingleId_do_not_update_last_execution()
|
||||
mocker.SetConstant(fakeJobs);
|
||||
|
||||
//Act
|
||||
var timerProvider = mocker.Resolve<JobProvider>();
|
||||
timerProvider.Initialize();
|
||||
timerProvider.QueueJob(typeof(FakeJob), 10);
|
||||
var jobProvider = mocker.Resolve<JobProvider>();
|
||||
jobProvider.Initialize();
|
||||
jobProvider.QueueJob(typeof(FakeJob), 10);
|
||||
Thread.Sleep(1000);
|
||||
|
||||
//Assert
|
||||
var settings = timerProvider.All();
|
||||
var settings = jobProvider.All();
|
||||
settings.Should().NotBeEmpty();
|
||||
settings[0].LastExecution.Should().HaveYear(2000);
|
||||
JobProvider.Queue.Should().BeEmpty();
|
||||
jobProvider.Queue.Should().BeEmpty();
|
||||
}
|
||||
|
||||
[Test]
|
||||
@ -386,13 +379,13 @@ public void SingleId_do_not_set_success()
|
||||
mocker.SetConstant(fakeJobs);
|
||||
|
||||
//Act
|
||||
var timerProvider = mocker.Resolve<JobProvider>();
|
||||
timerProvider.Initialize();
|
||||
timerProvider.QueueJob(typeof(FakeJob), 10);
|
||||
var jobProvider = mocker.Resolve<JobProvider>();
|
||||
jobProvider.Initialize();
|
||||
jobProvider.QueueJob(typeof(FakeJob), 10);
|
||||
Thread.Sleep(1000);
|
||||
|
||||
//Assert
|
||||
var settings = timerProvider.All();
|
||||
var settings = jobProvider.All();
|
||||
Assert.IsNotEmpty(settings);
|
||||
Assert.IsFalse(settings[0].Success);
|
||||
}
|
||||
@ -420,7 +413,7 @@ public void existing_queue_should_start_queue_if_not_running()
|
||||
//Act
|
||||
var jobProvider = mocker.Resolve<JobProvider>();
|
||||
jobProvider.Initialize();
|
||||
JobProvider.Queue.Add(fakeQueueItem);
|
||||
jobProvider.Queue.Add(fakeQueueItem);
|
||||
jobProvider.QueueJob(fakeJob.GetType(), 12);
|
||||
Thread.Sleep(1000);
|
||||
|
||||
@ -441,19 +434,21 @@ public void Item_added_to_queue_while_scheduler_runs_is_executed()
|
||||
mocker.SetConstant(MockLib.GetEmptyDatabase());
|
||||
mocker.SetConstant(fakeJobs);
|
||||
|
||||
mocker.Resolve<JobProvider>().Initialize();
|
||||
var jobProvider = mocker.Resolve<JobProvider>();
|
||||
|
||||
var _jobThread = new Thread(() => mocker.Resolve<JobProvider>().QueueScheduled());
|
||||
jobProvider.Initialize();
|
||||
|
||||
var _jobThread = new Thread(() => jobProvider.QueueScheduled());
|
||||
_jobThread.Start();
|
||||
|
||||
Thread.Sleep(200);
|
||||
|
||||
mocker.Resolve<JobProvider>().QueueJob(typeof(DisabledJob), 12);
|
||||
jobProvider.QueueJob(typeof(DisabledJob), 12);
|
||||
|
||||
Thread.Sleep(3000);
|
||||
|
||||
//Assert
|
||||
JobProvider.Queue.Should().BeEmpty();
|
||||
jobProvider.Queue.Should().BeEmpty();
|
||||
slowJob.ExecutionCount.Should().Be(1);
|
||||
disabledJob.ExecutionCount.Should().Be(1);
|
||||
}
|
||||
|
@ -61,10 +61,10 @@ private static void BindKernel()
|
||||
_kernel = new StandardKernel();
|
||||
|
||||
_kernel.Bind<IDatabase>().ToMethod(c => Connection.GetPetaPocoDb(Connection.MainConnectionString)).InTransientScope();
|
||||
//_kernel.Bind<IDatabase>().ToMethod(c => Connection.GetPetaPocoDb(Connection.MainConnectionString, false)).WhenInjectedInto<IJob>();
|
||||
//_kernel.Bind<IDatabase>().ToMethod(c => Connection.GetPetaPocoDb(Connection.MainConnectionString, false)).WhenInjectedInto<JobProvider>();
|
||||
_kernel.Bind<IDatabase>().ToMethod(c => Connection.GetPetaPocoDb(Connection.LogConnectionString, false)).WhenInjectedInto<DatabaseTarget>().InSingletonScope();
|
||||
_kernel.Bind<IDatabase>().ToMethod(c => Connection.GetPetaPocoDb(Connection.LogConnectionString)).WhenInjectedInto<LogProvider>().InSingletonScope();
|
||||
|
||||
_kernel.Bind<JobProvider>().ToSelf().InSingletonScope();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,11 +26,11 @@ public class JobProvider
|
||||
private readonly NotificationProvider _notificationProvider;
|
||||
private readonly IList<IJob> _jobs;
|
||||
|
||||
private static readonly object ExecutionLock = new object();
|
||||
private Thread _jobThread;
|
||||
private static bool _isRunning;
|
||||
|
||||
private static readonly List<JobQueueItem> _queue = new List<JobQueueItem>();
|
||||
private readonly object ExecutionLock = new object();
|
||||
private bool _isRunning;
|
||||
private readonly List<JobQueueItem> _queue = new List<JobQueueItem>();
|
||||
|
||||
private ProgressNotification _notification;
|
||||
|
||||
@ -49,11 +49,10 @@ public JobProvider(IDatabase database, NotificationProvider notificationProvider
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public JobProvider() { }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the active queue.
|
||||
/// </summary>
|
||||
public static List<JobQueueItem> Queue
|
||||
public List<JobQueueItem> Queue
|
||||
{
|
||||
get
|
||||
{
|
||||
|
@ -30,7 +30,7 @@ public SystemController(JobProvider jobProvider, IndexerProvider indexerProvider
|
||||
|
||||
public ActionResult Jobs()
|
||||
{
|
||||
ViewData["Queue"] = JobProvider.Queue.Select(c => new JobQueueItemModel {
|
||||
ViewData["Queue"] = _jobProvider.Queue.Select(c => new JobQueueItemModel {
|
||||
Name = c.JobType.Name,
|
||||
TargetId = c.TargetId,
|
||||
SecondaryTargetId = c.SecondaryTargetId
|
||||
|
Loading…
Reference in New Issue
Block a user