From 9cb33770a0edc41a3d4e21347a2a6d29571890ed Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Wed, 3 Aug 2011 09:29:03 -0700 Subject: [PATCH] Added Readme --- NzbDrone.Core.Test/JobProviderTest.cs | 18 +++---- NzbDrone.Core/Providers/Jobs/JobProvider.cs | 58 ++++++++++++++------- NzbDrone.Core/WebTimer.cs | 2 +- readme.md | 43 +++++++++++++++ 4 files changed, 93 insertions(+), 28 deletions(-) create mode 100644 readme.md diff --git a/NzbDrone.Core.Test/JobProviderTest.cs b/NzbDrone.Core.Test/JobProviderTest.cs index 9570e7716..81464dfe3 100644 --- a/NzbDrone.Core.Test/JobProviderTest.cs +++ b/NzbDrone.Core.Test/JobProviderTest.cs @@ -35,7 +35,7 @@ namespace NzbDrone.Core.Test //Act var timerProvider = mocker.Resolve(); timerProvider.Initialize(); - timerProvider.RunScheduled(); + timerProvider.QueueScheduled(); //Assert var settings = timerProvider.All(); @@ -56,7 +56,7 @@ namespace NzbDrone.Core.Test //Act var timerProvider = mocker.Resolve(); timerProvider.Initialize(); - timerProvider.RunScheduled(); + timerProvider.QueueScheduled(); Thread.Sleep(1000); @@ -79,9 +79,9 @@ namespace NzbDrone.Core.Test var timerProvider = mocker.Resolve(); timerProvider.Initialize(); - timerProvider.RunScheduled(); + timerProvider.QueueScheduled(); Thread.Sleep(500); - timerProvider.RunScheduled(); + timerProvider.QueueScheduled(); Thread.Sleep(500); fakeJob.ExexutionCount.Should().Be(1); @@ -174,10 +174,10 @@ namespace NzbDrone.Core.Test timerProvider.Initialize(); - var thread1 = new Thread(() => timerProvider.RunScheduled()); + var thread1 = new Thread(() => timerProvider.QueueScheduled()); thread1.Start(); Thread.Sleep(1000); - var thread2 = new Thread(() => timerProvider.RunScheduled()); + var thread2 = new Thread(() => timerProvider.QueueScheduled()); thread2.Start(); thread1.Join(); @@ -321,7 +321,7 @@ namespace NzbDrone.Core.Test //Act var timerProvider = mocker.Resolve(); timerProvider.Initialize(); - timerProvider.RunScheduled(); + timerProvider.QueueScheduled(); var next = timerProvider.NextScheduledRun(typeof(FakeJob)); //Assert @@ -346,7 +346,7 @@ namespace NzbDrone.Core.Test var timerProvider = mocker.Resolve(); timerProvider.Initialize(); - timerProvider.RunScheduled(); + timerProvider.QueueScheduled(); Thread.Sleep(1000); @@ -438,7 +438,7 @@ namespace NzbDrone.Core.Test mocker.Resolve().Initialize(); - var _jobThread = new Thread(() => mocker.Resolve().RunScheduled()); + var _jobThread = new Thread(() => mocker.Resolve().QueueScheduled()); _jobThread.Start(); Thread.Sleep(200); diff --git a/NzbDrone.Core/Providers/Jobs/JobProvider.cs b/NzbDrone.Core/Providers/Jobs/JobProvider.cs index 549fbd6fa..7715bfcd3 100644 --- a/NzbDrone.Core/Providers/Jobs/JobProvider.cs +++ b/NzbDrone.Core/Providers/Jobs/JobProvider.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Diagnostics; using System.Linq; using System.Threading; @@ -11,6 +12,10 @@ using PetaPoco; namespace NzbDrone.Core.Providers.Jobs { + /// + /// Provides a background task runner, tasks could be queue either by the scheduler using QueueScheduled() + /// or by explicitly calling QueueJob(type,int) + /// public class JobProvider { private static readonly Logger Logger = LogManager.GetCurrentClassLogger(); @@ -21,9 +26,8 @@ namespace NzbDrone.Core.Providers.Jobs private static readonly object ExecutionLock = new object(); private Thread _jobThread; private static bool _isRunning; - public static readonly List> Queue = new List>(); - + private static readonly List> _queue = new List>(); private ProgressNotification _notification; @@ -35,22 +39,38 @@ namespace NzbDrone.Core.Providers.Jobs _jobs = jobs; } + /// + /// Initializes a new instance of the class. by AutoMoq + /// + /// Should only be used by AutoMoq + [EditorBrowsable(EditorBrowsableState.Never)] public JobProvider() { } + + /// + /// Gets the active queue. + /// + public static List> Queue + { + get + { + return _queue; + } + } + /// /// Returns a list of all registered jobs /// - /// public virtual List All() { return _database.Fetch().ToList(); } /// - /// Creates/Updates definitions for a job + /// Adds/Updates definitions for a job /// - /// Settings to be created/updated - public virtual void SaveSettings(JobDefinition definitions) + /// Settings to be added/updated + public virtual void SaveDefinition(JobDefinition definitions) { if (definitions.Id == 0) { @@ -65,9 +85,10 @@ namespace NzbDrone.Core.Providers.Jobs } /// - /// Iterates through all registered jobs and executed any that are due for an execution. + /// Iterates through all registered jobs and queues any that are due for an execution. /// - public virtual void RunScheduled() + /// Will ignore request if queue is already running. + public virtual void QueueScheduled() { lock (ExecutionLock) { @@ -95,9 +116,9 @@ namespace NzbDrone.Core.Providers.Jobs } /// - /// Starts the execution of a job asynchronously + /// Queues the execution of a job asynchronously /// - /// Type of the job that should be executed. + /// Type of the job that should be queued. /// 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. /// Job is only added to the queue if same job with the same targetId doesn't already exist in the queue. @@ -119,7 +140,7 @@ namespace NzbDrone.Core.Providers.Jobs } else { - Logger.Info("[{0}:{1}] already exists in job queue. Skipping.", jobType.Name, targetId); + Logger.Info("[{0}:{1}] already exists in the queue. Skipping.", jobType.Name, targetId); } } @@ -163,7 +184,7 @@ namespace NzbDrone.Core.Providers.Jobs } /// - /// Starts processing of queue. + /// Starts processing of queue synchronously. /// private void ProcessQueue() { @@ -173,7 +194,7 @@ namespace NzbDrone.Core.Providers.Jobs using (NestedDiagnosticsContext.Push(Guid.NewGuid().ToString())) { - try + try { lock (Queue) { @@ -210,7 +231,7 @@ namespace NzbDrone.Core.Providers.Jobs } /// - /// Executes the job + /// Executes the job synchronously /// /// Type of the job that should be executed /// The targetId could be any Id parameter eg. SeriesId. it will be passed to the timer implementation @@ -256,15 +277,16 @@ namespace NzbDrone.Core.Providers.Jobs } } + //Only update last execution status if was triggered by the scheduler if (targetId == 0) { - SaveSettings(settings); + SaveDefinition(settings); } } /// /// Initializes jobs in the database using the IJob instances that are - /// registered in CentralDispatch + /// registered using ninject /// public virtual void Initialize() { @@ -285,13 +307,13 @@ namespace NzbDrone.Core.Providers.Jobs LastExecution = new DateTime(2000, 1, 1) }; - SaveSettings(settings); + SaveDefinition(settings); } } } /// - /// Gets the next scheduled run time for the job + /// Gets the next scheduled run time for a specific job /// (Estimated due to schedule timer) /// /// DateTime of next scheduled job execution diff --git a/NzbDrone.Core/WebTimer.cs b/NzbDrone.Core/WebTimer.cs index 3d326d5e7..03d940da6 100644 --- a/NzbDrone.Core/WebTimer.cs +++ b/NzbDrone.Core/WebTimer.cs @@ -30,7 +30,7 @@ namespace NzbDrone.Core public void DoWork(string k, object v, CacheItemRemovedReason r) { - _jobProvider.RunScheduled(); + _jobProvider.QueueScheduled(); StartTimer(Convert.ToInt32(v)); } } diff --git a/readme.md b/readme.md new file mode 100644 index 000000000..2a799291b --- /dev/null +++ b/readme.md @@ -0,0 +1,43 @@ +NZBDrone +===== + +*NZBDrone is currently in development. There may be severe bugs in it and at any given time it may not work at all.* + +NZBDrone is a PVR for newsgroup users written in .NET 4.0. It watches for new episodes of your favorite shows and when they are posted it downloads them, sorts and renames them. It retrieves show information from theTVDB.com. + +Features include: + +* automatically detects new episodes +* can scan your existing library and then download any old seasons that are missing +* can watch for better versions and upgrade your existing episodes (to from TV DVD/BluRay for example) +* fully configurable episode renaming +* sends NZBs directly to SABnzbd, prioritizes and categorizes them properly +* can notify XBMC, when new episodes are downloaded +* specials and double episode support + + +NZBDrone makes use of the following projects: + +## Platform +* [ASP.NET MVC 3.0](http://www.asp.net/mvc) +* [IIS Express](http://learn.iis.net/page.aspx/868/iis-express-overview/) +* [Microsoft SQL Server Compact 4.0](http://www.microsoft.com/download/en/details.aspx?id=17876) + +## Open Source Libraries +* [jQuery](http://jquery.com) +* [Ninject](http://ninject.org/) +* [NLog](http://nlog-project.org/) +* [PetaPoco](http://www.toptensoftware.com/petapoco/) +* [MVC Mini Profiler](http://code.google.com/p/mvc-mini-profiler/) +* [Migrator.NET](https://github.com/kayone/Migrator.NET) +* [Telerik Extensions for ASP.NET MVC](http://www.telerik.com/products/aspnet-mvc.aspx) +## Development Tools +* [Visual Studio 2010](http://www.microsoft.com/visualstudio/en-us/products/2010-editions) +* [ReSharper 6](http://www.jetbrains.com/resharper/index.html) +* [ANTS Performance Profiler](http://www.red-gate.com/products/dotnet-development/ants-performance-profiler/) +* [NUnit](http://www.nunit.org/) +* [Moq](http://code.google.com/p/moq/) +* [NBuilder](http://nbuilder.org/) +* [Fluent Assertions](http://fluentassertions.codeplex.com/) +* [TeamCity](http://www.jetbrains.com/teamcity/) +* [DotCover](http://www.jetbrains.com/dotcover/) \ No newline at end of file