This commit is contained in:
Jamie.Rees 2017-01-24 09:02:17 +00:00
commit ea52fa3dc3
24 changed files with 419 additions and 32 deletions

View file

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

View file

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

View file

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

View file

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

View file

@ -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);
}
}

View file

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

View file

@ -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();
}
}

View file

@ -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();
}
}

View file

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

View file

@ -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);
}
}
}
}

View file

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

View file

@ -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();
}
}
}

View file

@ -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()
{

View file

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

View file

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

View file

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

View file

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