1
0
mirror of https://github.com/Sonarr/Sonarr.git synced 2024-10-30 23:42:33 +01:00

moved jobcontroller to a blocking collection

This commit is contained in:
Keivan Beigi 2013-03-04 17:48:20 -08:00
parent 35cb7e55c7
commit 8ebcf0eb8b
4 changed files with 547 additions and 77 deletions

View File

@ -6,7 +6,6 @@ using FluentAssertions;
using Moq;
using NCrunch.Framework;
using NUnit.Framework;
using NzbDrone.Common;
using NzbDrone.Core.Jobs;
using NzbDrone.Core.Model;
using NzbDrone.Core.Test.Framework;
@ -21,6 +20,7 @@ namespace NzbDrone.Core.Test.JobTests
FakeJob _fakeJob;
SlowJob _slowJob;
SlowJob2 _slowJob2;
BrokenJob _brokenJob;
DisabledJob _disabledJob;
@ -32,11 +32,12 @@ namespace NzbDrone.Core.Test.JobTests
{
_fakeJob = new FakeJob();
_slowJob = new SlowJob();
_slowJob2 = new SlowJob2();
_brokenJob = new BrokenJob();
_disabledJob = new DisabledJob();
_updatedJob = null;
IEnumerable<IJob> jobs = new List<IJob> { _fakeJob, _slowJob, _brokenJob, _disabledJob };
IEnumerable<IJob> jobs = new List<IJob> { _fakeJob, _slowJob, _slowJob2, _brokenJob, _disabledJob };
Mocker.SetConstant(jobs);
@ -65,11 +66,11 @@ namespace NzbDrone.Core.Test.JobTests
private void WaitForQueue()
{
Console.WriteLine("Waiting for queue to clear.");
var stopWatch = Mocker.Resolve<JobController>().StopWatch;
var queue = Mocker.Resolve<JobController>().Queue;
while (stopWatch.IsRunning)
while (Subject.IsProcessing)
{
Thread.Sleep(10);
Thread.Sleep(100);
}
}
@ -113,16 +114,16 @@ namespace NzbDrone.Core.Test.JobTests
}
[Test]
public void no_concurent_jobs()
public void should_ignore_job_with_same_arg()
{
Subject.QueueJob(typeof(SlowJob), 1);
Subject.QueueJob(typeof(SlowJob), 2);
Subject.QueueJob(typeof(SlowJob), 3);
Subject.QueueJob(typeof(SlowJob2), 1);
Subject.QueueJob(typeof(FakeJob), 1);
Subject.QueueJob(typeof(FakeJob), 1);
WaitForQueue();
Subject.Queue.Should().BeEmpty();
_slowJob.ExecutionCount.Should().Be(3);
_fakeJob.ExecutionCount.Should().Be(1);
ExceptionVerification.AssertNoUnexcpectedLogs();
}
@ -182,11 +183,11 @@ namespace NzbDrone.Core.Test.JobTests
WaitForQueue();
Mocker.GetMock<IJobRepository>().Verify(c=>c.Update(It.IsAny<JobDefinition>()),Times.Never());
Mocker.GetMock<IJobRepository>().Verify(c => c.Update(It.IsAny<JobDefinition>()), Times.Never());
_updatedJob.Should().BeNull();
}
[Test]
public void Item_added_to_queue_while_scheduler_runs_should_be_executed()
@ -217,7 +218,7 @@ namespace NzbDrone.Core.Test.JobTests
[Test]
public void scheduled_job_should_have_scheduler_as_source()
{
GivenPendingJob(new List<JobDefinition> { new JobDefinition { TypeName = _slowJob.GetType().FullName }, new JobDefinition { TypeName = _slowJob.GetType().FullName } });
GivenPendingJob(new List<JobDefinition> { new JobDefinition { TypeName = _slowJob.GetType().FullName }, new JobDefinition { TypeName = _slowJob2.GetType().FullName } });
Subject.QueueScheduled();
Subject.Queue.Should().OnlyContain(c => c.Source == JobQueueItem.JobSourceType.Scheduler);

View File

@ -57,4 +57,12 @@ namespace NzbDrone.Core.Test.JobTests
Thread.Sleep(1000);
}
}
public class SlowJob2 : FakeJob
{
protected override void Start()
{
Thread.Sleep(1000);
}
}
}

View File

@ -54,6 +54,498 @@
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ParserTests\.ParserFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.InstrumentationTests\.DatabaseTargetFixture\..*</RegularExpression>
</RegexTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.InstrumentationTests.DatabaseTargetFixture.exception_log_with_no_message_should_use_exceptions_message</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.InstrumentationTests.DatabaseTargetFixture.write_log</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.InstrumentationTests.DatabaseTargetFixture.write_log_exception</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.InstrumentationTests.DatabaseTargetFixture.write_long_log</TestName>
</NamedTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.MediaFileTests\.MediaFileProvider_GetNewFilenameTest\..*</RegularExpression>
</RegexTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.GetNewFilename_Episode_Quality_1x05_Dash</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.GetNewFilename_Episode_Quality_1x05_Period</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.GetNewFilename_multi_1x05_Repeat_Dash_Period</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.GetNewFilename_multi_Episode_Quality_01x05_Repeat_Space</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.GetNewFilename_multi_Episode_Quality_1x05_Repeat_Dash</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.GetNewFilename_multi_Series_Episode_Quality_S01E05_Scene_Dash</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.GetNewFilename_multi_Series_Episode_s01e05_Duplicate_Period</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.GetNewFilename_multi_Series_S01E05_Extend_Dash_Period</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.GetNewFilename_S01E05_Dash</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.GetNewFilename_Series_Episode_Quality_S01E05_Dash</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.GetNewFilename_Series_Episode_Quality_S01E05_Period</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.GetNewFilename_Series_Episode_s01e05_Dash_Periods_Quality</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.GetNewFilename_Series_Episode_s01e05_Periods</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.GetNewFilename_Series_Quality_01x05_Space</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.GetNewFilename_Series_s01e05_Space</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.GetNewFilename_should_append_proper_when_proper_and_append_quality_is_true</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.GetNewFilename_should_not_append_proper_when_not_proper_and_append_quality_is_true</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.GetNewFilename_should_not_append_proper_when_proper_and_append_quality_is_false</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.GetNewFilename_should_order_multiple_episode_files_in_numerical_order</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.GetNewFilename_UseSceneName_when_sceneName_isNotNull</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.GetNewFilename_UseSceneName_when_sceneName_isNull</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.should_have_two_episodeTitles_when_distinct_count_is_two</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.should_have_two_episodeTitles_when_episode_titles_are_not_the_same</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.should_only_have_one_episodeTitle_when_episode_titles_are_the_same</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.should_set_airdate_to_unknown_if_not_available</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.should_use_airDate_if_series_isDaily</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.MediaFileTests.MediaFileProvider_GetNewFilenameTest.should_use_airDate_if_series_isDaily_no_episode_title</TestName>
</NamedTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.SceneMappingProviderTest\..*</RegularExpression>
</RegexTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.ProviderTests.SceneMappingProviderTest.GetSceneName_exists</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.ProviderTests.SceneMappingProviderTest.GetSceneName_multiple_clean_names</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.ProviderTests.SceneMappingProviderTest.GetSceneName_null</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.ProviderTests.SceneMappingProviderTest.GetSceneName_should_be_null_when_seasonNumber_does_not_match</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.ProviderTests.SceneMappingProviderTest.GetSeriesId_exists</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.ProviderTests.SceneMappingProviderTest.GetSeriesId_null</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.ProviderTests.SceneMappingProviderTest.UpdateMappings_should_add_all_mappings_to_database</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.ProviderTests.SceneMappingProviderTest.UpdateMappings_should_not_delete_if_csv_download_fails</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.ProviderTests.SceneMappingProviderTest.UpdateMappings_should_overwrite_existing_mappings</TestName>
</NamedTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.SearchTests\.GetSearchTitleFixture\..*</RegularExpression>
</RegexTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.ProviderTests.SearchTests.GetSearchTitleFixture.should_replace_ampersand_with_and</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.ProviderTests.SearchTests.GetSearchTitleFixture.should_replace_some_special_characters("Betty White\'s Off Their Rockers","Betty Whites Off Their Rockers")</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.ProviderTests.SearchTests.GetSearchTitleFixture.should_replace_some_special_characters("Hawaii Five-0","Hawaii Five-0")</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.ProviderTests.SearchTests.GetSearchTitleFixture.should_replace_some_special_characters("Star Wars: The Clone Wars","Star Wars The Clone Wars")</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.ProviderTests.SearchTests.GetSearchTitleFixture.should_return_scene_mapping_when_one_exists</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.ProviderTests.SearchTests.GetSearchTitleFixture.should_return_season_scene_name_when_one_exists</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.ProviderTests.SearchTests.GetSearchTitleFixture.should_return_series_scene_name_when_one_for_season_does_not_exist</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.ProviderTests.SearchTests.GetSearchTitleFixture.should_return_series_title_when_there_is_no_scene_mapping</TestName>
</NamedTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.SearchTests\.ProcessResultsFixture\..*</RegularExpression>
</RegexTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.ProviderTests.SearchTests.ProcessResultsFixture.should_check_other_reports_when_quality_is_not_wanted</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.ProviderTests.SearchTests.ProcessResultsFixture.should_process_higher_quality_results_first</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.ProviderTests.SearchTests.ProcessResultsFixture.should_process_newer_reports_first</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.ProviderTests.SearchTests.ProcessResultsFixture.should_return_valid_successes_when_one_or_more_downloaded</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.ProviderTests.SearchTests.ProcessResultsFixture.should_should_skip_if_series_is_not_watched</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.ProviderTests.SearchTests.ProcessResultsFixture.should_skip_if_episode_was_already_downloaded</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.ProviderTests.SearchTests.ProcessResultsFixture.should_skip_if_series_does_not_match_searched_series</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.ProviderTests.SearchTests.ProcessResultsFixture.should_try_next_report_if_download_fails</TestName>
</NamedTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.TvTests\.EpisodeProviderTests\.GetEpisodeBySceneNumberFixture\..*</RegularExpression>
</RegexTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.TvTests.EpisodeProviderTests.GetEpisodeBySceneNumberFixture.should_return_episode_if_matching_episode_is_found</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.TvTests.EpisodeProviderTests.GetEpisodeBySceneNumberFixture.should_return_null_if_no_episodes_in_db</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.TvTests.EpisodeProviderTests.GetEpisodeBySceneNumberFixture.should_return_null_if_no_matching_episode_is_found</TestName>
</NamedTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.TvTests\.SeasonProviderTest\..*</RegularExpression>
</RegexTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.TvTests.SeasonProviderTest.All_should_return_all_seasons_with_episodes</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.TvTests.SeasonProviderTest.All_should_return_seasons_with_episodes</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.TvTests.SeasonProviderTest.GetSeason_should_return_seasons_for_specified_series_only</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.TvTests.SeasonProviderTest.IsIgnored_should_return_ignored_status_of_season(False)</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.TvTests.SeasonProviderTest.IsIgnored_should_return_ignored_status_of_season(True)</TestName>
</NamedTestSelector>
<NamedTestSelector>
<TestName>NzbDrone.Core.Test.TvTests.SeasonProviderTest.IsIgnored_should_throw_an_exception_if_not_in_db</TestName>
</NamedTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.Datastore\.ObjectDatabaseFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.Datastore\.BasicRepositoryFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.DecisionEngineTests\.AcceptableSizeSpecificationFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.DecisionEngineTests\.AllowedDownloadSpecificationFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.DecisionEngineTests\.AllowedReleaseGroupSpecificationFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.DecisionEngineTests\.CustomStartDateSpecificationFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.DecisionEngineTests\.LanguageSpecificationFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.DecisionEngineTests\.MonitoredEpisodeSpecificationFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.DecisionEngineTests\.QualityAllowedByProfileSpecificationFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.DecisionEngineTests\.QualityUpgradeSpecificationFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.DecisionEngineTests\.RetentionSpecificationFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.DecisionEngineTests\.UpgradeDiskSpecificationFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.DecisionEngineTests\.UpgradeHistorySpecificationFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.DecisionEngineTests\.UpgradePossibleSpecificationFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.EpisodeParseResultTest\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.EpisodeStatusTest\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.FluentTest\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.HelperTests\.SortHelperTest\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.HelperTests\.XElementHelperTests\.ParseDayOfWeekFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.HelperTests\.XElementHelperTests\.XElementHelperTest\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.Indexers\.IndexerServiceTest\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.IndexerTests\.IndexerFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.IndexerTests\.NzbxFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.JobTests\.AppUpdateJobFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.JobTests\.BacklogSearchJobTest\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.JobTests\.DiskScanJobTest\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.JobTests\.ImportNewSeriesJobTest\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.JobTests\.JobRepositoryFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.JobTests\.PostDownloadScanJobFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.JobTests\.RecentBacklogSearchJobTest\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.JobTests\.RenameSeasonJobFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.JobTests\.RssSyncJobTest\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.JobTests\.SeasonSearchJobTest\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.JobTests\.SeriesSearchJobTest\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.DiskProviderTests\.ExtractArchiveFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.DiskProviderTests\.FreeDiskSpaceTest\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.DiskScanProviderTests\.CleanUpDropFolderFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.DiskScanProviderTests\.CleanUpFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.DiskScanProviderTests\.GetVideoFilesFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.DiskScanProviderTests\.ImportFileFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.DiskScanProviderTests\.MoveEpisodeFileFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.DiskScanProviderTests\.ScanFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.DownloadClientTests\.BlackholeProviderFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.DownloadClientTests\.NzbgetProviderTests\.DownloadNzbFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.DownloadClientTests\.NzbgetProviderTests\.QueueFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.DownloadClientTests\.PneumaticProviderFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.DownloadClientTests\.SabProviderTests\.QueueFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.DownloadClientTests\.SabProviderTests\.SabProviderFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.DownloadProviderTests\.ContainsRecentEpisode\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.DownloadProviderTests\.DownloadProviderFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.MediaFileTests\.MediaFileServiceTest\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.EventClientProviderTest\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.MisnamedProviderTest\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.NotificationProviderTests\.NotificationProviderFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.PlexProviderTest\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.PostDownloadProviderTests\.GetFolderNameWithStatusFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.PostDownloadProviderTests\.ProcessDownloadFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.PostDownloadProviderTests\.ProcessDropDirectoryFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.PostDownloadProviderTests\.ProcessVideoFileFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.RecycleBinProviderTests\.CleanupFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.RecycleBinProviderTests\.DeleteDirectoryFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.RecycleBinProviderTests\.DeleteFileFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.RecycleBinProviderTests\.EmptyFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.SearchTests\.DailyEpisodeSearchTests\.CheckReportFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.SearchTests\.DailyEpisodeSearchTests\.PerformSearchFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.SearchTests\.EpisodeSearchTests\.CheckReportFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.SearchTests\.EpisodeSearchTests\.PerformSearchFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.SearchTests\.PartialSeasonSearchTests\.CheckReportFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.SearchTests\.PartialSeasonSearchTests\.PerformSearchFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.TvRageMappingProviderTests\.FindMatchingTvRageSeriesFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.TvRageMappingProviderTests\.ProcessResultsFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.TvRageProviderTests\.GetSeriesFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.TvRageProviderTests\.GetUtcOffsetFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.TvRageProviderTests\.SearchSeriesFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.UpdateProviderTests\.GetAvilableUpdateFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.UpdateProviderTests\.GetUpdateLogFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.XbmcProviderTest\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.XemCommunicationProviderTests\.GetSceneTvdbMappingsFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.ProviderTests\.XemCommunicationProviderTests\.GetXemSeriesIdsFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.RootFolderTests\.FreeSpaceOnDrivesFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.RootFolderTests\.RootFolderServiceFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.Indexers\.NewznabProviderTest\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.HistoryTests\.HistoryServiceTest\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.Configuration\.ConfigServiceFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.Configuration\.ConfigCachingFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.TvTests\.SeriesProviderTest\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.XbmcVersionTests\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.MediaFileTests\.MediaFileRepositoryFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.Qualities\.QualityFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.Qualities\.QualityProfileFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.Qualities\.QualitySizeServiceFixture\..*</RegularExpression>
</RegexTestSelector>
<RegexTestSelector>
<RegularExpression>NzbDrone\.Core\.Test\.TvTests\.QualityModelFixture\..*</RegularExpression>
</RegexTestSelector>
</IgnoredTests>
<HiddenWarnings>PostBuildEventDisabled;PreBuildEventDisabled</HiddenWarnings>
</ProjectConfiguration>

View File

@ -1,10 +1,10 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using NLog;
using NzbDrone.Core.Lifecycle;
using NzbDrone.Core.Model;
using NzbDrone.Core.Model.Notification;
using NzbDrone.Core.Providers;
@ -13,32 +13,31 @@ namespace NzbDrone.Core.Jobs
{
public interface IJobController
{
Stopwatch StopWatch { get; }
List<JobQueueItem> Queue { get; }
bool IsProcessing { get; }
IEnumerable<JobQueueItem> Queue { get; }
void QueueScheduled();
void QueueJob(Type jobType, dynamic options = null, JobQueueItem.JobSourceType source = JobQueueItem.JobSourceType.User);
bool QueueJob(string jobTypeString);
}
public class JobController : IJobController, IInitializable
public class JobController : IJobController
{
private readonly NotificationProvider _notificationProvider;
private readonly IEnumerable<IJob> _jobs;
private readonly IJobRepository _jobRepository;
private readonly Logger _logger;
private Timer _timer;
private Thread _jobThread;
public Stopwatch StopWatch { get; private set; }
private readonly object _executionLock = new object();
private readonly List<JobQueueItem> _queue = new List<JobQueueItem>();
private readonly BlockingCollection<JobQueueItem> _queue = new BlockingCollection<JobQueueItem>();
private ProgressNotification _notification;
public JobController(NotificationProvider notificationProvider, IEnumerable<IJob> jobs, IJobRepository jobRepository, Logger logger)
{
StopWatch = new Stopwatch();
_notificationProvider = notificationProvider;
_jobs = jobs;
_jobRepository = jobRepository;
@ -46,13 +45,10 @@ namespace NzbDrone.Core.Jobs
ResetThread();
}
public void Init()
{
_timer = new Timer(c => QueueScheduled());
_timer.Change(0, 60 * 1000);
}
public List<JobQueueItem> Queue
public bool IsProcessing { get; private set; }
public IEnumerable<JobQueueItem> Queue
{
get
{
@ -64,8 +60,6 @@ namespace NzbDrone.Core.Jobs
{
lock (_executionLock)
{
VerifyThreadTime();
if (_jobThread.IsAlive)
{
_logger.Trace("Queue is already running. Ignoring scheduler's request.");
@ -84,6 +78,8 @@ namespace NzbDrone.Core.Jobs
public virtual void QueueJob(Type jobType, dynamic options = null, JobQueueItem.JobSourceType source = JobQueueItem.JobSourceType.User)
{
IsProcessing = true;
var queueItem = new JobQueueItem
{
JobType = jobType,
@ -95,18 +91,16 @@ namespace NzbDrone.Core.Jobs
lock (_executionLock)
{
VerifyThreadTime();
lock (Queue)
lock (_queue)
{
if (!Queue.Contains(queueItem))
if (!_queue.Contains(queueItem))
{
Queue.Add(queueItem);
_logger.Trace("Job {0} added to the queue. current items in queue: {1}", queueItem, Queue.Count);
_queue.Add(queueItem);
_logger.Trace("Job {0} added to the queue. current items in queue: {1}", queueItem, _queue.Count);
}
else
{
_logger.Info("{0} already exists in the queue. Skipping. current items in queue: {1}", queueItem, Queue.Count);
_logger.Info("{0} already exists in the queue. Skipping. current items in queue: {1}", queueItem, _queue.Count);
}
}
@ -117,7 +111,6 @@ namespace NzbDrone.Core.Jobs
}
ResetThread();
StopWatch = Stopwatch.StartNew();
_jobThread.Start();
}
@ -138,40 +131,25 @@ namespace NzbDrone.Core.Jobs
{
try
{
do
while (true)
{
using (NestedDiagnosticsContext.Push(Guid.NewGuid().ToString()))
IsProcessing = false;
var item = _queue.Take();
IsProcessing = true;
try
{
try
{
JobQueueItem job = null;
lock (Queue)
{
if (Queue.Count != 0)
{
job = Queue.OrderBy(c => c.Source).First();
_logger.Trace("Popping {0} from the queue.", job);
Queue.Remove(job);
}
}
if (job != null)
{
Execute(job);
}
}
catch (ThreadAbortException)
{
throw;
}
catch (Exception e)
{
_logger.FatalException("An error has occurred while executing job.", e);
}
Execute(item);
}
} while (Queue.Count != 0);
catch (ThreadAbortException)
{
throw;
}
catch (Exception e)
{
_logger.FatalException("An error has occurred while executing job.", e);
}
}
}
catch (ThreadAbortException e)
{
@ -183,7 +161,6 @@ namespace NzbDrone.Core.Jobs
}
finally
{
StopWatch.Stop();
_logger.Trace("Finished processing jobs in the queue.");
}
}
@ -239,14 +216,6 @@ namespace NzbDrone.Core.Jobs
}
}
private void VerifyThreadTime()
{
if (StopWatch.Elapsed.TotalHours > 1)
{
_logger.Warn("Thread job has been running for more than an hour. fuck it!");
ResetThread();
}
}
private void ResetThread()
{