Added Readme

This commit is contained in:
kay.one 2011-08-03 09:29:03 -07:00
parent 2c3da2c5ea
commit 9cb33770a0
4 changed files with 93 additions and 28 deletions

View File

@ -35,7 +35,7 @@ namespace NzbDrone.Core.Test
//Act
var timerProvider = mocker.Resolve<JobProvider>();
timerProvider.Initialize();
timerProvider.RunScheduled();
timerProvider.QueueScheduled();
//Assert
var settings = timerProvider.All();
@ -56,7 +56,7 @@ namespace NzbDrone.Core.Test
//Act
var timerProvider = mocker.Resolve<JobProvider>();
timerProvider.Initialize();
timerProvider.RunScheduled();
timerProvider.QueueScheduled();
Thread.Sleep(1000);
@ -79,9 +79,9 @@ namespace NzbDrone.Core.Test
var timerProvider = mocker.Resolve<JobProvider>();
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<JobProvider>();
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<JobProvider>();
timerProvider.Initialize();
timerProvider.RunScheduled();
timerProvider.QueueScheduled();
Thread.Sleep(1000);
@ -438,7 +438,7 @@ namespace NzbDrone.Core.Test
mocker.Resolve<JobProvider>().Initialize();
var _jobThread = new Thread(() => mocker.Resolve<JobProvider>().RunScheduled());
var _jobThread = new Thread(() => mocker.Resolve<JobProvider>().QueueScheduled());
_jobThread.Start();
Thread.Sleep(200);

View File

@ -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
{
/// <summary>
/// Provides a background task runner, tasks could be queue either by the scheduler using QueueScheduled()
/// or by explicitly calling QueueJob(type,int)
/// </summary>
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<Tuple<Type, Int32>> Queue = new List<Tuple<Type, int>>();
private static readonly List<Tuple<Type, Int32>> _queue = new List<Tuple<Type, int>>();
private ProgressNotification _notification;
@ -35,22 +39,38 @@ namespace NzbDrone.Core.Providers.Jobs
_jobs = jobs;
}
/// <summary>
/// Initializes a new instance of the <see cref="JobProvider"/> class. by AutoMoq
/// </summary>
/// <remarks>Should only be used by AutoMoq</remarks>
[EditorBrowsable(EditorBrowsableState.Never)]
public JobProvider() { }
/// <summary>
/// Gets the active queue.
/// </summary>
public static List<Tuple<Type, Int32>> Queue
{
get
{
return _queue;
}
}
/// <summary>
/// Returns a list of all registered jobs
/// </summary>
/// <returns></returns>
public virtual List<JobDefinition> All()
{
return _database.Fetch<JobDefinition>().ToList();
}
/// <summary>
/// Creates/Updates definitions for a job
/// Adds/Updates definitions for a job
/// </summary>
/// <param name="definitions">Settings to be created/updated</param>
public virtual void SaveSettings(JobDefinition definitions)
/// <param name="definitions">Settings to be added/updated</param>
public virtual void SaveDefinition(JobDefinition definitions)
{
if (definitions.Id == 0)
{
@ -65,9 +85,10 @@ namespace NzbDrone.Core.Providers.Jobs
}
/// <summary>
/// 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.
/// </summary>
public virtual void RunScheduled()
/// <remarks>Will ignore request if queue is already running.</remarks>
public virtual void QueueScheduled()
{
lock (ExecutionLock)
{
@ -95,9 +116,9 @@ namespace NzbDrone.Core.Providers.Jobs
}
/// <summary>
/// Starts the execution of a job asynchronously
/// Queues the execution of a job asynchronously
/// </summary>
/// <param name="jobType">Type of the job that should be executed.</param>
/// <param name="jobType">Type of the job that should be queued.</param>
/// <param name="targetId">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.</param>
/// <remarks>Job is only added to the queue if same job with the same targetId doesn't already exist in the queue.</remarks>
@ -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
}
/// <summary>
/// Starts processing of queue.
/// Starts processing of queue synchronously.
/// </summary>
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
}
/// <summary>
/// Executes the job
/// Executes the job synchronously
/// </summary>
/// <param name="jobType">Type of the job that should be executed</param>
/// <param name="targetId">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);
}
}
/// <summary>
/// Initializes jobs in the database using the IJob instances that are
/// registered in CentralDispatch
/// registered using ninject
/// </summary>
public virtual void Initialize()
{
@ -285,13 +307,13 @@ namespace NzbDrone.Core.Providers.Jobs
LastExecution = new DateTime(2000, 1, 1)
};
SaveSettings(settings);
SaveDefinition(settings);
}
}
}
/// <summary>
/// Gets the next scheduled run time for the job
/// Gets the next scheduled run time for a specific job
/// (Estimated due to schedule timer)
/// </summary>
/// <returns>DateTime of next scheduled job execution</returns>

View File

@ -30,7 +30,7 @@ namespace NzbDrone.Core
public void DoWork(string k, object v, CacheItemRemovedReason r)
{
_jobProvider.RunScheduled();
_jobProvider.QueueScheduled();
StartTimer(Convert.ToInt32(v));
}
}

43
readme.md Normal file
View File

@ -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/)