started on #646. Fixed #657

pull/687/head
Jamie.Rees 8 years ago
parent 84ea45ebaa
commit 05bdfcd550

@ -25,6 +25,7 @@
// ************************************************************************/
#endregion
using System;
using System.Data;
using System.Linq;
using PlexRequests.Helpers.Permissions;
@ -36,12 +37,14 @@ namespace PlexRequests.Core.Migration.Migrations
[Migration(11000, "v1.10.0.0")]
public class Version1100 : BaseMigration, IMigration
{
public Version1100(IUserRepository userRepo)
public Version1100(IUserRepository userRepo, IRequestService requestService)
{
UserRepo = userRepo;
RequestService = requestService;
}
public int Version => 11000;
private IUserRepository UserRepo { get; }
private IRequestService RequestService { get; }
public void Start(IDbConnection con)
{
@ -50,6 +53,7 @@ namespace PlexRequests.Core.Migration.Migrations
// Update the current admin permissions set
UpdateAdmin();
UpdateSchema(con, Version);
}
@ -59,6 +63,26 @@ namespace PlexRequests.Core.Migration.Migrations
con.AlterTable("Users", "ADD", "Permissions", true, "INTEGER");
con.AlterTable("Users", "ADD", "Features", true, "INTEGER");
// Add the new 'running' item into the scheduled jobs so we can check if the cachers are running
con.AlterTable("ScheduledJobs", "ADD", "Running", true, "INTEGER");
//https://image.tmdb.org/t/p/w150/https://image.tmdb.org/t/p/w150//aqhAqttDq7zgsTaBHtCD8wmTk6k.jpg
// UI = https://image.tmdb.org/t/p/w150/{{posterPath}}
// Update old invalid posters
var allRequests = RequestService.GetAll().ToList();
foreach (var req in allRequests)
{
if (req.PosterPath.Contains("https://image.tmdb.org/t/p/w150/"))
{
var newImg = req.PosterPath.Replace("https://image.tmdb.org/t/p/w150/", string.Empty);
req.PosterPath = newImg;
}
}
RequestService.BatchUpdate(allRequests);
}
private void UpdateAdmin()

@ -30,7 +30,7 @@ namespace PlexRequests.Core
{
public struct TimeFrameMinutes
{
public const int SchedulerCaching = 60;
public const int SchedulerCaching = 120;
}
public const string PlexLibaries = nameof(PlexLibaries);

@ -36,5 +36,6 @@ namespace PlexRequests.Services.Interfaces
void Record(string jobName);
Task<IEnumerable<ScheduledJobs>> GetJobsAsync();
IEnumerable<ScheduledJobs> GetJobs();
void SetRunning(bool running, string jobName);
}
}

@ -81,6 +81,7 @@ namespace PlexRequests.Services.Jobs
finally
{
Job.Record(JobNames.CpCacher);
Job.SetRunning(false, JobNames.CpCacher);
}
}
}
@ -108,6 +109,7 @@ namespace PlexRequests.Services.Jobs
public void Execute(IJobExecutionContext context)
{
Job.SetRunning(true, JobNames.CpCacher);
Queued();
}
}

@ -87,6 +87,8 @@ namespace PlexRequests.Services.Jobs
public void Execute(IJobExecutionContext context)
{
Record.SetRunning(true, JobNames.CpCacher);
try
{
var faultedRequests = Repo.GetAll().ToList();
@ -105,6 +107,7 @@ namespace PlexRequests.Services.Jobs
finally
{
Record.Record(JobNames.FaultQueueHandler);
Record.SetRunning(false, JobNames.CpCacher);
}
}

@ -60,6 +60,23 @@ namespace PlexRequests.Services.Jobs
}
}
public void SetRunning(bool running, string jobName)
{
var allJobs = Repo.GetAll();
var storeJob = allJobs.FirstOrDefault(x => x.Name == jobName);
if (storeJob != null)
{
storeJob.Running = running;
Repo.Update(storeJob);
}
else
{
var job = new ScheduledJobs { Running = running, Name = jobName };
Repo.Insert(job);
}
}
public async Task<IEnumerable<ScheduledJobs>> GetJobsAsync()
{
return await Repo.GetAllAsync();

@ -158,7 +158,7 @@ namespace PlexRequests.Services.Jobs
}
Job.Record(JobNames.PlexChecker);
Job.SetRunning(false, JobNames.CpCacher);
}
public List<PlexMovie> GetPlexMovies()
@ -503,6 +503,8 @@ namespace PlexRequests.Services.Jobs
public void Execute(IJobExecutionContext context)
{
Job.SetRunning(true, JobNames.CpCacher);
try
{
CheckAndUpdateAll();

@ -145,6 +145,7 @@ namespace PlexRequests.Services.Jobs
public void Execute(IJobExecutionContext context)
{
Job.SetRunning(true, JobNames.CpCacher);
try
{
var s = Plex.GetSettings();
@ -171,6 +172,7 @@ namespace PlexRequests.Services.Jobs
finally
{
Job.Record(JobNames.EpisodeCacher);
Job.SetRunning(false, JobNames.CpCacher);
}
}
}

@ -78,6 +78,8 @@ namespace PlexRequests.Services.Jobs
public void Execute(IJobExecutionContext context)
{
JobRecord.SetRunning(true, JobNames.CpCacher);
try
{
var settings = NewsletterSettings.GetSettings();
@ -95,6 +97,7 @@ namespace PlexRequests.Services.Jobs
finally
{
JobRecord.Record(JobNames.RecentlyAddedEmail);
JobRecord.SetRunning(false, JobNames.CpCacher);
}
}

@ -58,6 +58,7 @@ namespace PlexRequests.Services.Jobs
public void Queued()
{
Job.SetRunning(true, JobNames.CpCacher);
Log.Trace("Getting the settings");
var settings = SrSettings.GetSettings();
@ -79,6 +80,7 @@ namespace PlexRequests.Services.Jobs
finally
{
Job.Record(JobNames.SrCacher);
Job.SetRunning(false, JobNames.CpCacher);
}
}
}

@ -62,6 +62,7 @@ namespace PlexRequests.Services.Jobs
public void Queued()
{
Job.SetRunning(true, JobNames.CpCacher);
var settings = SonarrSettings.GetSettings();
if (settings.Enabled)
{
@ -80,6 +81,7 @@ namespace PlexRequests.Services.Jobs
finally
{
Job.Record(JobNames.SonarrCacher);
Job.SetRunning(false, JobNames.CpCacher);
}
}
}

@ -53,6 +53,7 @@ namespace PlexRequests.Services.Jobs
public void Execute(IJobExecutionContext context)
{
JobRecord.SetRunning(true, JobNames.CpCacher);
TakeBackup();
Cleanup();
}
@ -91,6 +92,7 @@ namespace PlexRequests.Services.Jobs
finally
{
JobRecord.Record(JobNames.StoreBackup);
JobRecord.SetRunning(false, JobNames.CpCacher);
}
}

@ -78,12 +78,14 @@ namespace PlexRequests.Services.Jobs
finally
{
JobRecord.Record(JobNames.StoreCleanup);
JobRecord.SetRunning(false, JobNames.CpCacher);
}
}
public void Execute(IJobExecutionContext context)
{
JobRecord.SetRunning(true, JobNames.CpCacher);
Cleanup();
}
}

@ -98,6 +98,7 @@ namespace PlexRequests.Services.Jobs
public void Execute(IJobExecutionContext context)
{
Record.SetRunning(true, JobNames.CpCacher);
try
{
var settings = Settings.GetSettings();
@ -115,6 +116,7 @@ namespace PlexRequests.Services.Jobs
finally
{
Record.Record(JobNames.RequestLimitReset);
Record.SetRunning(false, JobNames.CpCacher);
}
}
}

@ -35,5 +35,6 @@ namespace PlexRequests.Store.Models
{
public string Name { get; set; }
public DateTime LastRun { get; set; }
public bool Running { get; set; }
}
}

@ -80,7 +80,8 @@ CREATE TABLE IF NOT EXISTS ScheduledJobs
(
Id INTEGER PRIMARY KEY AUTOINCREMENT,
Name varchar(100) NOT NULL,
LastRun varchar(100) NOT NULL
LastRun varchar(100) NOT NULL,
Running INTEGER
);
CREATE UNIQUE INDEX IF NOT EXISTS ScheduledJobs_Id ON ScheduledJobs (Id);

Loading…
Cancel
Save