Added the transaction back into the DB.

Do not run the episode cacher if it's been run in the last hour
This commit is contained in:
tidusjar 2016-08-08 13:38:26 +01:00
commit d19deea56c
3 changed files with 19 additions and 17 deletions

View file

@ -49,13 +49,14 @@ namespace PlexRequests.Services.Jobs
public class PlexEpisodeCacher : IJob
{
public PlexEpisodeCacher(ISettingsService<PlexSettings> plexSettings, IPlexApi plex, ICacheProvider cache,
IJobRecord rec, IRepository<PlexEpisodes> repo)
IJobRecord rec, IRepository<PlexEpisodes> repo, ISettingsService<ScheduledJobsSettings> jobs)
{
Plex = plexSettings;
PlexApi = plex;
Cache = cache;
Job = rec;
Repo = repo;
Jobs = jobs;
}
private ISettingsService<PlexSettings> Plex { get; }
@ -64,6 +65,7 @@ namespace PlexRequests.Services.Jobs
private ICacheProvider Cache { get; }
private IJobRecord Job { get; }
private IRepository<PlexEpisodes> Repo { get; }
private ISettingsService<ScheduledJobsSettings> Jobs { get; }
private const int ResultCount = 25;
private const string PlexType = "episode";
private const string TableName = "PlexEpisodes";
@ -142,6 +144,15 @@ namespace PlexRequests.Services.Jobs
{
try
{
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(-1)) // If it's been run in the last hour
{
return;
}
}
CacheEpisodes();
}
catch (Exception e)