Merge pull request #983 from tidusjar/dev

Done #627
pull/1028/head
Jamie 8 years ago committed by GitHub
commit bbd08cbfec

@ -34,6 +34,7 @@ namespace Ombi.Services.Interfaces
{
public interface IAvailabilityChecker
{
void Start();
void CheckAndUpdateAll();
IEnumerable<PlexContent> GetPlexMovies(IEnumerable<PlexContent> content);
bool IsMovieAvailable(PlexContent[] plexMovies, string title, string year, string providerId = null);

@ -6,5 +6,6 @@ namespace Ombi.Services.Jobs
{
void Execute(IJobExecutionContext context);
void Test();
void Start();
}
}

@ -0,0 +1,10 @@
using Quartz;
namespace Ombi.Services.Jobs
{
public interface IStoreBackup
{
void Start();
void Execute(IJobExecutionContext context);
}
}

@ -0,0 +1,10 @@
using Quartz;
namespace Ombi.Services.Jobs
{
public interface IStoreCleanup
{
void Execute(IJobExecutionContext context);
void Start();
}
}

@ -0,0 +1,16 @@
using System.Collections.Generic;
using Ombi.Core.SettingModels;
using Ombi.Store.Models;
using Quartz;
namespace Ombi.Services.Jobs
{
public interface IUserRequestLimitResetter
{
void AlbumLimit(PlexRequestSettings s, IEnumerable<RequestLimit> allUsers);
void Execute(IJobExecutionContext context);
void MovieLimit(PlexRequestSettings s, IEnumerable<RequestLimit> allUsers);
void Start();
void TvLimit(PlexRequestSettings s, IEnumerable<RequestLimit> allUsers);
}
}

@ -45,7 +45,7 @@ using Quartz;
namespace Ombi.Services.Jobs
{
public class FaultQueueHandler : IJob
public class FaultQueueHandler : IJob, IFaultQueueHandler
{
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
@ -91,9 +91,8 @@ namespace Ombi.Services.Jobs
private ISettingsService<HeadphonesSettings> HeadphoneSettings { get; }
private ISecurityExtensions Security { get; }
public void Execute(IJobExecutionContext context)
public void Start()
{
Record.SetRunning(true, JobNames.CpCacher);
try
{
@ -116,6 +115,11 @@ namespace Ombi.Services.Jobs
Record.SetRunning(false, JobNames.CpCacher);
}
}
public void Execute(IJobExecutionContext context)
{
Start();
}
private void ProcessMissingInformation(List<RequestQueue> requests)

@ -0,0 +1,14 @@
using System.Collections.Generic;
using Ombi.Core.SettingModels;
using Ombi.Store;
using Quartz;
namespace Ombi.Services.Jobs
{
public interface IFaultQueueHandler
{
void Execute(IJobExecutionContext context);
bool ShouldAutoApprove(RequestType requestType, PlexRequestSettings prSettings, List<string> username);
void Start();
}
}

@ -0,0 +1,12 @@
using Ombi.Core.SettingModels;
using Quartz;
namespace Ombi.Services.Jobs
{
public interface IPlexEpisodeCacher
{
void CacheEpisodes(PlexSettings settings);
void Execute(IJobExecutionContext context);
void Start();
}
}

@ -0,0 +1,10 @@
using Quartz;
namespace Ombi.Services.Jobs
{
public interface IPlexUserChecker
{
void Execute(IJobExecutionContext context);
void Start();
}
}

@ -473,5 +473,23 @@ namespace Ombi.Services.Jobs
Job.SetRunning(false, JobNames.PlexChecker);
}
}
public void Start()
{
Job.SetRunning(true, JobNames.PlexChecker);
try
{
CheckAndUpdateAll();
}
catch (Exception e)
{
Log.Error(e);
}
finally
{
Job.Record(JobNames.PlexChecker);
Job.SetRunning(false, JobNames.PlexChecker);
}
}
}
}

@ -43,7 +43,7 @@ using Quartz;
namespace Ombi.Services.Jobs
{
public class PlexEpisodeCacher : IJob
public class PlexEpisodeCacher : IJob, IPlexEpisodeCacher
{
public PlexEpisodeCacher(ISettingsService<PlexSettings> plexSettings, IPlexApi plex, ICacheProvider cache,
IJobRecord rec, IRepository<PlexEpisodes> repo, ISettingsService<ScheduledJobsSettings> jobs)
@ -140,6 +140,38 @@ namespace Ombi.Services.Jobs
}
}
public void Start()
{
try
{
var s = Plex.GetSettings();
if (!s.EnableTvEpisodeSearching)
{
return;
}
var jobs = Job.GetJobs();
var job = jobs.FirstOrDefault(x => x.Name.Equals(JobNames.EpisodeCacher, StringComparison.CurrentCultureIgnoreCase));
if (job != null)
{
if (job.LastRun > DateTime.Now.AddHours(-11)) // If it's been run in the last 11 hours
{
return;
}
}
Job.SetRunning(true, JobNames.EpisodeCacher);
CacheEpisodes(s);
}
catch (Exception e)
{
Log.Error(e);
}
finally
{
Job.Record(JobNames.EpisodeCacher);
Job.SetRunning(false, JobNames.EpisodeCacher);
}
}
public void Execute(IJobExecutionContext context)
{

@ -42,7 +42,7 @@ using Quartz;
namespace Ombi.Services.Jobs
{
public class PlexUserChecker : IJob
public class PlexUserChecker : IJob, IPlexUserChecker
{
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
@ -68,7 +68,7 @@ namespace Ombi.Services.Jobs
private IRequestService RequestService { get; }
private IUserRepository LocalUserRepository { get; }
public void Execute(IJobExecutionContext context)
public void Start()
{
JobRecord.SetRunning(true, JobNames.PlexUserChecker);
@ -153,7 +153,7 @@ namespace Ombi.Services.Jobs
}
// Looks like it's a new user!
var m = new PlexUsers
var m = new PlexUsers
{
PlexUserId = user.Id,
Permissions = UserManagementHelper.GetPermissions(userManagementSettings),
@ -170,7 +170,7 @@ namespace Ombi.Services.Jobs
// Main Plex user
var dbMainAcc = dbUsers.FirstOrDefault(x => x.Username.Equals(mainPlexAccount.Username, StringComparison.CurrentCulture));
var localMainAcc = localUsers.FirstOrDefault(x => x.UserName.Equals(mainPlexAccount.Username, StringComparison.CurrentCulture));
// TODO if admin acc does exist, check if we need to update it
@ -188,7 +188,7 @@ namespace Ombi.Services.Jobs
LoginId = Guid.NewGuid().ToString()
};
a.Permissions += (int) Permissions.Administrator; // Make admin
a.Permissions += (int)Permissions.Administrator; // Make admin
Repo.Insert(a);
}
@ -205,5 +205,9 @@ namespace Ombi.Services.Jobs
JobRecord.Record(JobNames.PlexUserChecker);
}
}
public void Execute(IJobExecutionContext context)
{
Start();
}
}
}

@ -78,7 +78,7 @@ namespace Ombi.Services.Jobs
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
public void Execute(IJobExecutionContext context)
public void Start()
{
try
{
@ -100,6 +100,10 @@ namespace Ombi.Services.Jobs
JobRecord.SetRunning(false, JobNames.RecentlyAddedEmail);
}
}
public void Execute(IJobExecutionContext context)
{
Start();
}
public void Test()
{

@ -35,7 +35,7 @@ using Quartz;
namespace Ombi.Services.Jobs
{
public class StoreBackup : IJob
public class StoreBackup : IJob, IStoreBackup
{
public StoreBackup(ISqliteConfiguration sql, IJobRecord rec)
{
@ -48,6 +48,13 @@ namespace Ombi.Services.Jobs
private static Logger Log = LogManager.GetCurrentClassLogger();
public void Start()
{
JobRecord.SetRunning(true, JobNames.CpCacher);
TakeBackup();
Cleanup();
}
public void Execute(IJobExecutionContext context)
{
JobRecord.SetRunning(true, JobNames.CpCacher);

@ -36,7 +36,7 @@ using Quartz;
namespace Ombi.Services.Jobs
{
public class StoreCleanup : IJob
public class StoreCleanup : IJob, IStoreCleanup
{
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
@ -81,6 +81,11 @@ namespace Ombi.Services.Jobs
}
public void Start()
{
JobRecord.SetRunning(true, JobNames.CpCacher);
Cleanup();
}
public void Execute(IJobExecutionContext context)
{
JobRecord.SetRunning(true, JobNames.CpCacher);

@ -39,7 +39,7 @@ using Quartz;
namespace Ombi.Services.Jobs
{
public class UserRequestLimitResetter : IJob
public class UserRequestLimitResetter : IJob, IUserRequestLimitResetter
{
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
@ -94,6 +94,31 @@ namespace Ombi.Services.Jobs
}
}
public void Start()
{
Record.SetRunning(true, JobNames.CpCacher);
try
{
var settings = Settings.GetSettings();
var users = Repo.GetAll();
var requestLimits = users as RequestLimit[] ?? users.ToArray();
MovieLimit(settings, requestLimits);
TvLimit(settings, requestLimits);
AlbumLimit(settings, requestLimits);
}
catch (Exception e)
{
Log.Error(e);
}
finally
{
Record.Record(JobNames.RequestLimitReset);
Record.SetRunning(false, JobNames.CpCacher);
}
}
public void Execute(IJobExecutionContext context)
{
Record.SetRunning(true, JobNames.CpCacher);

@ -90,11 +90,17 @@
<Compile Include="Interfaces\IWatcherCacher.cs" />
<Compile Include="Interfaces\IJobRecord.cs" />
<Compile Include="Interfaces\INotificationEngine.cs" />
<Compile Include="Interfaces\IStoreBackup.cs" />
<Compile Include="Interfaces\IStoreCleanup.cs" />
<Compile Include="Interfaces\IUserRequestLimitResetter.cs" />
<Compile Include="Jobs\IFaultQueueHandler.cs" />
<Compile Include="Jobs\IPlexEpisodeCacher.cs" />
<Compile Include="Jobs\IPlexUserChecker.cs" />
<Compile Include="Jobs\RadarrCacher.cs" />
<Compile Include="Jobs\WatcherCacher.cs" />
<Compile Include="Jobs\HtmlTemplateGenerator.cs" />
<Compile Include="Jobs\IPlexContentCacher.cs" />
<Compile Include="Jobs\IRecentlyAdded.cs" />
<Compile Include="Interfaces\IPlexContentCacher.cs" />
<Compile Include="Interfaces\IRecentlyAdded.cs" />
<Compile Include="Jobs\JobRecord.cs" />
<Compile Include="Jobs\JobNames.cs" />
<Compile Include="Jobs\PlexContentCacher.cs" />

@ -8,7 +8,7 @@
return s;
}
$(function() {
$(function () {
$('[data-toggle="tooltip"]').tooltip();
});
@ -93,6 +93,19 @@ function createBaseUrl(base, url) {
return url;
}
function createBaseUrl(url) {
var base = $('#baseUrl').text();
if (base) {
if (url.charAt(0) === "/") {
url = "/" + base + url;
} else {
url = "/" + base + "/" + url;
}
}
return url;
}
var noResultsHtml = "<div class='no-search-results'>" +
"<i class='fa fa-film no-search-results-icon'></i><div class='no-search-results-text'>Sorry, we didn't find any results!</div></div>";
var noResultsMusic = "<div class='no-search-results'>" +

@ -0,0 +1,150 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: AboutModule.cs
// Created By: Jamie Rees
//
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// ************************************************************************/
#endregion
using System;
using System.Threading.Tasks;
using Nancy;
using Ombi.Core;
using Ombi.Core.SettingModels;
using Ombi.Helpers.Permissions;
using Ombi.Services.Interfaces;
using Ombi.Services.Jobs;
using Ombi.UI.Models;
using ISecurityExtensions = Ombi.Core.ISecurityExtensions;
namespace Ombi.UI.Modules.Admin
{
public class ScheduledJobsRunnerModule : BaseModule
{
public ScheduledJobsRunnerModule(ISettingsService<PlexRequestSettings> settingsService,
ISecurityExtensions security, IPlexContentCacher contentCacher, ISonarrCacher sonarrCacher, IWatcherCacher watcherCacher,
IRadarrCacher radarrCacher, ICouchPotatoCacher cpCacher, IStoreBackup store, ISickRageCacher srCacher, IAvailabilityChecker plexChceker,
IStoreCleanup cleanup, IUserRequestLimitResetter requestLimit, IPlexEpisodeCacher episodeCacher, IRecentlyAdded recentlyAdded,
IFaultQueueHandler faultQueueHandler, IPlexUserChecker plexUserChecker) : base("admin", settingsService, security)
{
Before += (ctx) => Security.AdminLoginRedirect(Permissions.Administrator, ctx);
PlexContentCacher = contentCacher;
SonarrCacher = sonarrCacher;
RadarrCacher = radarrCacher;
WatcherCacher = watcherCacher;
CpCacher = cpCacher;
StoreBackup = store;
SrCacher = srCacher;
AvailabilityChecker = plexChceker;
StoreCleanup = cleanup;
RequestLimit = requestLimit;
EpisodeCacher = episodeCacher;
RecentlyAdded = recentlyAdded;
FaultQueueHandler = faultQueueHandler;
PlexUserChecker = plexUserChecker;
Post["/schedulerun", true] = async (x, ct) => await ScheduleRun((string)Request.Form.key);
}
private IPlexContentCacher PlexContentCacher { get; }
private IRadarrCacher RadarrCacher { get; }
private ISonarrCacher SonarrCacher { get; }
private IWatcherCacher WatcherCacher { get; }
private ICouchPotatoCacher CpCacher { get; }
private IStoreBackup StoreBackup { get; }
private ISickRageCacher SrCacher { get; }
private IAvailabilityChecker AvailabilityChecker { get; }
private IStoreCleanup StoreCleanup { get; }
private IUserRequestLimitResetter RequestLimit { get; }
private IPlexEpisodeCacher EpisodeCacher { get; }
private IRecentlyAdded RecentlyAdded { get; }
private IFaultQueueHandler FaultQueueHandler { get; }
private IPlexUserChecker PlexUserChecker { get; }
private async Task<Response> ScheduleRun(string key)
{
if (key.Equals(JobNames.PlexCacher, StringComparison.CurrentCultureIgnoreCase))
{
PlexContentCacher.CacheContent();
}
if (key.Equals(JobNames.WatcherCacher, StringComparison.CurrentCultureIgnoreCase))
{
WatcherCacher.Queued();
}
if (key.Equals(JobNames.SonarrCacher, StringComparison.CurrentCultureIgnoreCase))
{
SonarrCacher.Queued();
}
if (key.Equals(JobNames.RadarrCacher, StringComparison.CurrentCultureIgnoreCase))
{
RadarrCacher.Queued();
}
if (key.Equals(JobNames.CpCacher, StringComparison.CurrentCultureIgnoreCase))
{
CpCacher.Queued();
}
if (key.Equals(JobNames.StoreBackup, StringComparison.CurrentCultureIgnoreCase))
{
StoreBackup.Start();
}
if (key.Equals(JobNames.SrCacher, StringComparison.CurrentCultureIgnoreCase))
{
SrCacher.Queued();
}
if (key.Equals(JobNames.PlexChecker, StringComparison.CurrentCultureIgnoreCase))
{
AvailabilityChecker.Start();
}
if (key.Equals(JobNames.StoreCleanup, StringComparison.CurrentCultureIgnoreCase))
{
StoreCleanup.Start();
}
if (key.Equals(JobNames.RequestLimitReset, StringComparison.CurrentCultureIgnoreCase))
{
RequestLimit.Start();
}
if (key.Equals(JobNames.EpisodeCacher, StringComparison.CurrentCultureIgnoreCase))
{
EpisodeCacher.Start();
}
if (key.Equals(JobNames.RecentlyAddedEmail, StringComparison.CurrentCultureIgnoreCase))
{
RecentlyAdded.Start();
}
if (key.Equals(JobNames.FaultQueueHandler, StringComparison.CurrentCultureIgnoreCase))
{
FaultQueueHandler.Start();
}
if (key.Equals(JobNames.PlexUserChecker, StringComparison.CurrentCultureIgnoreCase))
{
RequestLimit.Start();
}
return Response.AsJson(new JsonResponseModel { Result = true });
}
}
}

@ -52,6 +52,12 @@ namespace Ombi.UI.NinjectModules
Bind<IPlexContentCacher>().To<PlexContentCacher>();
Bind<IJobFactory>().To<CustomJobFactory>();
Bind<IMovieSender>().To<MovieSender>();
Bind<IStoreBackup>().To<StoreBackup>();
Bind<IStoreCleanup>().To<StoreCleanup>();
Bind<IUserRequestLimitResetter>().To<UserRequestLimitResetter>();
Bind<IPlexEpisodeCacher>().To<PlexEpisodeCacher>();
Bind<IFaultQueueHandler>().To<FaultQueueHandler>();
Bind<IPlexUserChecker>().To<PlexUserChecker>();
Bind<IAnalytics>().To<Analytics>();
Bind<ISchedulerFactory>().To<StdSchedulerFactory>();

@ -258,6 +258,7 @@
<Compile Include="Models\UI\Dropdown.cs" />
<Compile Include="Models\UserManagement\DeleteUserViewModel.cs" />
<Compile Include="Models\UserManagement\UserUpdateViewModel.cs" />
<Compile Include="Modules\Admin\ScheduledJobsRunnerModule.cs" />
<Compile Include="Modules\Admin\AboutModule.cs" />
<Compile Include="Modules\Admin\CustomizationModule.cs" />
<Compile Include="Modules\Admin\IntegrationModule.cs" />

@ -3,22 +3,32 @@
<div class="col-sm-8 col-sm-push-1">
<table class="table table-striped table-hover table-responsive table-condensed">
<thead>
<tr>
<td>Job Name</td>
<td>Last Run</td>
<td></td>
</tr>
</thead>
<tbody>
@foreach (var record in Model.JobRecorder)
{
<tr>
<td>
@record.Key
</td>
<td>
@record.Value.ToString("R")
</td>
<td class="refresh" id="@record.Key"><i class="fa fa-refresh"></i></td>
</tr>
}
</tbody>
</table>
<div class="row">
<div class="col-md-4"><strong>Job Name</strong>
</div>
<div class="col-md-6 col-md-push-3"><strong>Last Run</strong>
</div>
</div>
<hr style="margin-top: 4px; margin-bottom: 4px"/>
@foreach (var record in Model.JobRecorder)
{
<div class="row">
<div class="col-md-4">@record.Key</div>
<div class="col-md-5 col-md-push-3 date">@record.Value.ToString("R")</div>
</div>
<hr style="margin-top: 4px; margin-bottom: 4px"/>
}
<br/>
<br/>
<form class="form-horizontal" method="POST" id="mainForm">
@ -122,6 +132,34 @@
$obj.text(newDate);
});
$('.refresh').click(function(e) {
var id = e.currentTarget.id;
var ev = $(e.currentTarget.children[0]);
ev.addClass("fa-spin");
var url = createBaseUrl("/admin/schedulerun");
$.ajax({
type: 'POST',
data: {key:id},
url: url,
dataType: "json",
success: function (response) {
if (response.result === true) {
generateNotify("Success!", "success");
} else {
generateNotify(response.message, "warning");
}
},
error: function (e) {
console.log(e);
generateNotify("Something went wrong!", "danger");
}
});
});
$('#save')
.click(function (e) {
e.preventDefault();

@ -2,7 +2,7 @@
@Html.Partial("Shared/Partial/_Sidebar")
<div class="col-sm-8 col-sm-push-1">
<fieldset>
<legend>Release Fault Queue</legend>
<legend>Request Fault Queue</legend>
<table class="table table-striped table-hover table-responsive table-condensed">
<thead>

Loading…
Cancel
Save