mirror of
https://github.com/Radarr/Radarr.git
synced 2024-11-13 22:43:35 +01:00
Merge branch 'master' of git://github.com/kayone/NzbDrone
This commit is contained in:
commit
45b4bb4629
@ -35,7 +35,7 @@ public void Run_Jobs_Updates_Last_Execution()
|
|||||||
//Act
|
//Act
|
||||||
var timerProvider = mocker.Resolve<JobProvider>();
|
var timerProvider = mocker.Resolve<JobProvider>();
|
||||||
timerProvider.Initialize();
|
timerProvider.Initialize();
|
||||||
timerProvider.RunScheduled();
|
timerProvider.QueueScheduled();
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
var settings = timerProvider.All();
|
var settings = timerProvider.All();
|
||||||
@ -56,7 +56,7 @@ public void Run_Jobs_Updates_Last_Execution_Mark_as_unsuccesful()
|
|||||||
//Act
|
//Act
|
||||||
var timerProvider = mocker.Resolve<JobProvider>();
|
var timerProvider = mocker.Resolve<JobProvider>();
|
||||||
timerProvider.Initialize();
|
timerProvider.Initialize();
|
||||||
timerProvider.RunScheduled();
|
timerProvider.QueueScheduled();
|
||||||
|
|
||||||
Thread.Sleep(1000);
|
Thread.Sleep(1000);
|
||||||
|
|
||||||
@ -79,9 +79,9 @@ public void scheduler_skips_jobs_that_arent_mature_yet()
|
|||||||
|
|
||||||
var timerProvider = mocker.Resolve<JobProvider>();
|
var timerProvider = mocker.Resolve<JobProvider>();
|
||||||
timerProvider.Initialize();
|
timerProvider.Initialize();
|
||||||
timerProvider.RunScheduled();
|
timerProvider.QueueScheduled();
|
||||||
Thread.Sleep(500);
|
Thread.Sleep(500);
|
||||||
timerProvider.RunScheduled();
|
timerProvider.QueueScheduled();
|
||||||
Thread.Sleep(500);
|
Thread.Sleep(500);
|
||||||
|
|
||||||
fakeJob.ExexutionCount.Should().Be(1);
|
fakeJob.ExexutionCount.Should().Be(1);
|
||||||
@ -174,10 +174,10 @@ public void can_run_two_jobs_at_the_same_time()
|
|||||||
timerProvider.Initialize();
|
timerProvider.Initialize();
|
||||||
|
|
||||||
|
|
||||||
var thread1 = new Thread(() => timerProvider.RunScheduled());
|
var thread1 = new Thread(() => timerProvider.QueueScheduled());
|
||||||
thread1.Start();
|
thread1.Start();
|
||||||
Thread.Sleep(1000);
|
Thread.Sleep(1000);
|
||||||
var thread2 = new Thread(() => timerProvider.RunScheduled());
|
var thread2 = new Thread(() => timerProvider.QueueScheduled());
|
||||||
thread2.Start();
|
thread2.Start();
|
||||||
|
|
||||||
thread1.Join();
|
thread1.Join();
|
||||||
@ -321,7 +321,7 @@ public void Get_Next_Execution_Time()
|
|||||||
//Act
|
//Act
|
||||||
var timerProvider = mocker.Resolve<JobProvider>();
|
var timerProvider = mocker.Resolve<JobProvider>();
|
||||||
timerProvider.Initialize();
|
timerProvider.Initialize();
|
||||||
timerProvider.RunScheduled();
|
timerProvider.QueueScheduled();
|
||||||
var next = timerProvider.NextScheduledRun(typeof(FakeJob));
|
var next = timerProvider.NextScheduledRun(typeof(FakeJob));
|
||||||
|
|
||||||
//Assert
|
//Assert
|
||||||
@ -346,7 +346,7 @@ public void Disabled_isnt_run_by_scheduler()
|
|||||||
var timerProvider = mocker.Resolve<JobProvider>();
|
var timerProvider = mocker.Resolve<JobProvider>();
|
||||||
timerProvider.Initialize();
|
timerProvider.Initialize();
|
||||||
|
|
||||||
timerProvider.RunScheduled();
|
timerProvider.QueueScheduled();
|
||||||
|
|
||||||
Thread.Sleep(1000);
|
Thread.Sleep(1000);
|
||||||
|
|
||||||
@ -438,7 +438,7 @@ public void Item_added_to_queue_while_scheduler_runs_is_executed()
|
|||||||
|
|
||||||
mocker.Resolve<JobProvider>().Initialize();
|
mocker.Resolve<JobProvider>().Initialize();
|
||||||
|
|
||||||
var _jobThread = new Thread(() => mocker.Resolve<JobProvider>().RunScheduled());
|
var _jobThread = new Thread(() => mocker.Resolve<JobProvider>().QueueScheduled());
|
||||||
_jobThread.Start();
|
_jobThread.Start();
|
||||||
|
|
||||||
Thread.Sleep(200);
|
Thread.Sleep(200);
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
@ -11,6 +12,10 @@
|
|||||||
|
|
||||||
namespace NzbDrone.Core.Providers.Jobs
|
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
|
public class JobProvider
|
||||||
{
|
{
|
||||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||||
@ -21,9 +26,8 @@ public class JobProvider
|
|||||||
private static readonly object ExecutionLock = new object();
|
private static readonly object ExecutionLock = new object();
|
||||||
private Thread _jobThread;
|
private Thread _jobThread;
|
||||||
private static bool _isRunning;
|
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;
|
private ProgressNotification _notification;
|
||||||
|
|
||||||
@ -35,22 +39,38 @@ public JobProvider(IDatabase database, NotificationProvider notificationProvider
|
|||||||
_jobs = 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() { }
|
public JobProvider() { }
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets the active queue.
|
||||||
|
/// </summary>
|
||||||
|
public static List<Tuple<Type, Int32>> Queue
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _queue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns a list of all registered jobs
|
/// Returns a list of all registered jobs
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
|
||||||
public virtual List<JobDefinition> All()
|
public virtual List<JobDefinition> All()
|
||||||
{
|
{
|
||||||
return _database.Fetch<JobDefinition>().ToList();
|
return _database.Fetch<JobDefinition>().ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates/Updates definitions for a job
|
/// Adds/Updates definitions for a job
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="definitions">Settings to be created/updated</param>
|
/// <param name="definitions">Settings to be added/updated</param>
|
||||||
public virtual void SaveSettings(JobDefinition definitions)
|
public virtual void SaveDefinition(JobDefinition definitions)
|
||||||
{
|
{
|
||||||
if (definitions.Id == 0)
|
if (definitions.Id == 0)
|
||||||
{
|
{
|
||||||
@ -65,9 +85,10 @@ public virtual void SaveSettings(JobDefinition definitions)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
public virtual void RunScheduled()
|
/// <remarks>Will ignore request if queue is already running.</remarks>
|
||||||
|
public virtual void QueueScheduled()
|
||||||
{
|
{
|
||||||
lock (ExecutionLock)
|
lock (ExecutionLock)
|
||||||
{
|
{
|
||||||
@ -95,9 +116,9 @@ public virtual void RunScheduled()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Starts the execution of a job asynchronously
|
/// Queues the execution of a job asynchronously
|
||||||
/// </summary>
|
/// </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
|
/// <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>
|
/// 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>
|
/// <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 @@ public virtual void QueueJob(Type jobType, int targetId = 0)
|
|||||||
}
|
}
|
||||||
else
|
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 @@ public virtual void QueueJob(Type jobType, int targetId = 0)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Starts processing of queue.
|
/// Starts processing of queue synchronously.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void ProcessQueue()
|
private void ProcessQueue()
|
||||||
{
|
{
|
||||||
@ -210,7 +231,7 @@ private void ProcessQueue()
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Executes the job
|
/// Executes the job synchronously
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="jobType">Type of the job that should be executed</param>
|
/// <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
|
/// <param name="targetId">The targetId could be any Id parameter eg. SeriesId. it will be passed to the timer implementation
|
||||||
@ -256,15 +277,16 @@ private void Execute(Type jobType, int targetId = 0)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Only update last execution status if was triggered by the scheduler
|
||||||
if (targetId == 0)
|
if (targetId == 0)
|
||||||
{
|
{
|
||||||
SaveSettings(settings);
|
SaveDefinition(settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Initializes jobs in the database using the IJob instances that are
|
/// Initializes jobs in the database using the IJob instances that are
|
||||||
/// registered in CentralDispatch
|
/// registered using ninject
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public virtual void Initialize()
|
public virtual void Initialize()
|
||||||
{
|
{
|
||||||
@ -285,13 +307,13 @@ public virtual void Initialize()
|
|||||||
LastExecution = new DateTime(2000, 1, 1)
|
LastExecution = new DateTime(2000, 1, 1)
|
||||||
};
|
};
|
||||||
|
|
||||||
SaveSettings(settings);
|
SaveDefinition(settings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <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)
|
/// (Estimated due to schedule timer)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>DateTime of next scheduled job execution</returns>
|
/// <returns>DateTime of next scheduled job execution</returns>
|
||||||
|
@ -30,7 +30,7 @@ public void StartTimer(int secondInterval)
|
|||||||
|
|
||||||
public void DoWork(string k, object v, CacheItemRemovedReason r)
|
public void DoWork(string k, object v, CacheItemRemovedReason r)
|
||||||
{
|
{
|
||||||
_jobProvider.RunScheduled();
|
_jobProvider.QueueScheduled();
|
||||||
StartTimer(Convert.ToInt32(v));
|
StartTimer(Convert.ToInt32(v));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
43
readme.md
Normal file
43
readme.md
Normal 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/)
|
Loading…
Reference in New Issue
Block a user