mirror of
https://github.com/Radarr/Radarr.git
synced 2024-08-16 23:39:44 +02:00
JobProvider now stores last execution and success
JobProvider is now wired working Job view ui is updated
This commit is contained in:
parent
6f73260ab7
commit
fa1b287d58
@ -13,7 +13,7 @@ namespace NzbDrone.Core.Test
|
||||
public class JobProviderTest
|
||||
{
|
||||
[Test]
|
||||
public void Run_Jobs()
|
||||
public void Run_Jobs_Updates_Last_Execution()
|
||||
{
|
||||
|
||||
IEnumerable<IJob> fakeTimers = new List<IJob> { new FakeJob() };
|
||||
@ -22,10 +22,38 @@ public void Run_Jobs()
|
||||
mocker.SetConstant(MockLib.GetEmptyRepository());
|
||||
mocker.SetConstant(fakeTimers);
|
||||
|
||||
//Act
|
||||
var timerProvider = mocker.Resolve<JobProvider>();
|
||||
timerProvider.Initialize();
|
||||
timerProvider.RunScheduled();
|
||||
|
||||
//Assert
|
||||
var settings = timerProvider.All();
|
||||
Assert.IsNotEmpty(settings);
|
||||
Assert.AreNotEqual(DateTime.MinValue, settings[0].LastExecution);
|
||||
Assert.IsTrue(settings[0].Success);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void Run_Jobs_Updates_Last_Execution_Mark_as_unsuccesful()
|
||||
{
|
||||
|
||||
IEnumerable<IJob> fakeTimers = new List<IJob> { new BrokenJob() };
|
||||
var mocker = new AutoMoqer();
|
||||
|
||||
mocker.SetConstant(MockLib.GetEmptyRepository());
|
||||
mocker.SetConstant(fakeTimers);
|
||||
|
||||
//Act
|
||||
var timerProvider = mocker.Resolve<JobProvider>();
|
||||
timerProvider.Initialize();
|
||||
timerProvider.RunScheduled();
|
||||
|
||||
//Assert
|
||||
var settings = timerProvider.All();
|
||||
Assert.IsNotEmpty(settings);
|
||||
Assert.AreNotEqual(DateTime.MinValue, settings[0].LastExecution);
|
||||
Assert.IsFalse(settings[0].Success);
|
||||
}
|
||||
|
||||
|
||||
@ -222,7 +250,7 @@ public int DefaultInterval
|
||||
|
||||
public void Start(ProgressNotification notification, int targetId)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -98,6 +98,7 @@ public static void BindKernel()
|
||||
_kernel.Bind<MediaFileProvider>().ToSelf().InSingletonScope();
|
||||
_kernel.Bind<JobProvider>().ToSelf().InSingletonScope();
|
||||
_kernel.Bind<IndexerProvider>().ToSelf().InSingletonScope();
|
||||
_kernel.Bind<WebTimer>().ToSelf().InSingletonScope();
|
||||
_kernel.Bind<IRepository>().ToMethod(
|
||||
c => new SimpleRepository(dbProvider, SimpleRepositoryOptions.RunMigrations)).InSingletonScope();
|
||||
|
||||
@ -130,9 +131,9 @@ private static void BindJobs()
|
||||
_kernel.Bind<IJob>().To<RssSyncJob>().InTransientScope();
|
||||
_kernel.Bind<IJob>().To<NewSeriesUpdate>().InTransientScope();
|
||||
_kernel.Bind<IJob>().To<UpdateInfoJob>().InTransientScope();
|
||||
|
||||
_kernel.Get<JobProvider>().Initialize();
|
||||
|
||||
new WebTimer().StartTimer(1);
|
||||
_kernel.Get<WebTimer>().StartTimer(30);
|
||||
}
|
||||
|
||||
|
||||
|
@ -87,8 +87,6 @@ public virtual bool RunScheduled()
|
||||
|
||||
foreach (var pendingTimer in pendingJobs)
|
||||
{
|
||||
Logger.Info("Attempting to start job [{0}]. Last executing {1}", pendingTimer.Name,
|
||||
pendingTimer.LastExecution);
|
||||
var timerClass = _jobs.Where(t => t.GetType().ToString() == pendingTimer.TypeName).FirstOrDefault();
|
||||
Execute(timerClass.GetType(), 0);
|
||||
}
|
||||
@ -162,12 +160,16 @@ private void Execute(Type jobType, int targetId = 0)
|
||||
var timerClass = _jobs.Where(t => t.GetType() == jobType).FirstOrDefault();
|
||||
if (timerClass == null)
|
||||
{
|
||||
Logger.Error("Unable to locate implantation for [{0}]. Make sure its properly registered.", jobType.ToString());
|
||||
Logger.Error("Unable to locate implantation for '{0}'. Make sure its properly registered.", jobType.ToString());
|
||||
return;
|
||||
}
|
||||
|
||||
var settings = All().Where(j => j.TypeName == jobType.ToString()).FirstOrDefault();
|
||||
|
||||
try
|
||||
{
|
||||
Logger.Info("Starting job '{0}'. Last execution {1}", settings.Name, settings.LastExecution);
|
||||
settings.LastExecution = DateTime.Now;
|
||||
var sw = Stopwatch.StartNew();
|
||||
using (_notification = new ProgressNotification(timerClass.Name))
|
||||
{
|
||||
@ -175,13 +177,17 @@ private void Execute(Type jobType, int targetId = 0)
|
||||
timerClass.Start(_notification, targetId);
|
||||
_notification.Status = ProgressNotificationStatus.Completed;
|
||||
}
|
||||
settings.Success = true;
|
||||
sw.Stop();
|
||||
Logger.Info("timer [{0}] finished executing successfully. Duration {1}", timerClass.Name, sw.Elapsed.ToString());
|
||||
Logger.Info("Job '{0}' successfully completed in {1} seconds", timerClass.Name, sw.Elapsed.Minutes, sw.Elapsed.Seconds);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
settings.Success = false;
|
||||
Logger.ErrorException("An error has occurred while executing timer job " + timerClass.Name, e);
|
||||
}
|
||||
|
||||
SaveSettings(settings);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -5,15 +5,22 @@
|
||||
using System.Web;
|
||||
using System.Web.Caching;
|
||||
using NLog;
|
||||
using NzbDrone.Core.Providers.Jobs;
|
||||
|
||||
namespace NzbDrone.Core
|
||||
{
|
||||
class WebTimer
|
||||
{
|
||||
private readonly JobProvider _jobProvider;
|
||||
|
||||
private static CacheItemRemovedCallback _onCacheRemove;
|
||||
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
|
||||
|
||||
public WebTimer(JobProvider jobProvider)
|
||||
{
|
||||
_jobProvider = jobProvider;
|
||||
}
|
||||
|
||||
public void StartTimer(int secondInterval)
|
||||
{
|
||||
_onCacheRemove = new CacheItemRemovedCallback(DoWork);
|
||||
@ -26,7 +33,7 @@ public void StartTimer(int secondInterval)
|
||||
|
||||
public void DoWork(string k, object v, CacheItemRemovedReason r)
|
||||
{
|
||||
Logger.Info("Tick!");
|
||||
_jobProvider.RunScheduled();
|
||||
StartTimer(Convert.ToInt32(v));
|
||||
}
|
||||
}
|
||||
|
@ -40,6 +40,7 @@ public ActionResult _AjaxBinding()
|
||||
{
|
||||
|
||||
//TODO: possible subsonic bug, IQuarible causes some issues so ToList() is called
|
||||
//https://github.com/subsonic/SubSonic-3.0/issues/263
|
||||
|
||||
var history = _historyProvider.AllItems().ToList().Select(h => new HistoryModel
|
||||
{
|
||||
|
@ -7,11 +7,11 @@
|
||||
|
||||
namespace NzbDrone.Web.Controllers
|
||||
{
|
||||
public class TimersController : Controller
|
||||
public class JobController : Controller
|
||||
{
|
||||
private readonly JobProvider _jobProvider;
|
||||
|
||||
public TimersController(JobProvider jobProvider)
|
||||
public JobController(JobProvider jobProvider)
|
||||
{
|
||||
_jobProvider = jobProvider;
|
||||
}
|
@ -219,7 +219,7 @@
|
||||
<Compile Include="Controllers\SeriesController.cs" />
|
||||
<Compile Include="Controllers\SettingsController.cs" />
|
||||
<Compile Include="Controllers\SharedController.cs" />
|
||||
<Compile Include="Controllers\TimersController.cs" />
|
||||
<Compile Include="Controllers\JobController.cs" />
|
||||
<Compile Include="Controllers\UpcomingController.cs" />
|
||||
<Compile Include="Global.asax.cs">
|
||||
<DependentUpon>Global.asax</DependentUpon>
|
||||
@ -660,7 +660,7 @@
|
||||
<Content Include="Scripts\jquery.validate.unobtrusive.min.js" />
|
||||
<Content Include="Views\Web.config" />
|
||||
<Content Include="Views\Settings\Indexers.cshtml" />
|
||||
<Content Include="Views\Timers\index.cshtml" />
|
||||
<Content Include="Views\Job\index.cshtml" />
|
||||
<Content Include="Views\Settings\Downloads.cshtml" />
|
||||
<Content Include="Views\Settings\EpisodeSorting.cshtml" />
|
||||
<Content Include="Views\Settings\General.cshtml" />
|
||||
|
9
NzbDrone.Web/Views/Job/index.cshtml
Normal file
9
NzbDrone.Web/Views/Job/index.cshtml
Normal file
@ -0,0 +1,9 @@
|
||||
@model IEnumerable<NzbDrone.Core.Repository.JobSetting>
|
||||
@section TitleContent{
|
||||
Jobs
|
||||
}
|
||||
@section MainContent{
|
||||
@{Html.Telerik().Grid(Model).Name("Grid")
|
||||
.TableHtmlAttributes(new { @class = "Grid" })
|
||||
.Render();}
|
||||
}
|
@ -1,59 +0,0 @@
|
||||
@model IEnumerable<NzbDrone.Core.Repository.JobSetting>
|
||||
@{
|
||||
Layout = null;
|
||||
}
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Timers</title>
|
||||
</head>
|
||||
<body>
|
||||
<table>
|
||||
<tr>
|
||||
<th>
|
||||
</th>
|
||||
<th>
|
||||
Enable
|
||||
</th>
|
||||
<th>
|
||||
TypeName
|
||||
</th>
|
||||
<th>
|
||||
Name
|
||||
</th>
|
||||
<th>
|
||||
Interval
|
||||
</th>
|
||||
<th>
|
||||
LastExecution
|
||||
</th>
|
||||
<th>
|
||||
Success
|
||||
</th>
|
||||
</tr>
|
||||
@foreach (var item in Model)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
@item.Enable
|
||||
</td>
|
||||
<td>
|
||||
@item.TypeName
|
||||
</td>
|
||||
<td>
|
||||
@item.Name
|
||||
</td>
|
||||
<td>
|
||||
@item.Interval
|
||||
</td>
|
||||
<td>
|
||||
@String.Format("{0:g}", item.LastExecution)
|
||||
</td>
|
||||
<td>
|
||||
@item.Success
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user