mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-12 08:16:05 -07:00
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:
parent
0b21c69a46
commit
d19deea56c
3 changed files with 19 additions and 17 deletions
|
@ -37,7 +37,7 @@ namespace PlexRequests.Core.SettingModels
|
||||||
StoreBackup = 24;
|
StoreBackup = 24;
|
||||||
StoreCleanup = 24;
|
StoreCleanup = 24;
|
||||||
UserRequestLimitResetter = 12;
|
UserRequestLimitResetter = 12;
|
||||||
PlexEpisodeCacher = 2;
|
PlexEpisodeCacher = 12;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int PlexAvailabilityChecker { get; set; }
|
public int PlexAvailabilityChecker { get; set; }
|
||||||
|
|
|
@ -49,13 +49,14 @@ namespace PlexRequests.Services.Jobs
|
||||||
public class PlexEpisodeCacher : IJob
|
public class PlexEpisodeCacher : IJob
|
||||||
{
|
{
|
||||||
public PlexEpisodeCacher(ISettingsService<PlexSettings> plexSettings, IPlexApi plex, ICacheProvider cache,
|
public PlexEpisodeCacher(ISettingsService<PlexSettings> plexSettings, IPlexApi plex, ICacheProvider cache,
|
||||||
IJobRecord rec, IRepository<PlexEpisodes> repo)
|
IJobRecord rec, IRepository<PlexEpisodes> repo, ISettingsService<ScheduledJobsSettings> jobs)
|
||||||
{
|
{
|
||||||
Plex = plexSettings;
|
Plex = plexSettings;
|
||||||
PlexApi = plex;
|
PlexApi = plex;
|
||||||
Cache = cache;
|
Cache = cache;
|
||||||
Job = rec;
|
Job = rec;
|
||||||
Repo = repo;
|
Repo = repo;
|
||||||
|
Jobs = jobs;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ISettingsService<PlexSettings> Plex { get; }
|
private ISettingsService<PlexSettings> Plex { get; }
|
||||||
|
@ -64,6 +65,7 @@ namespace PlexRequests.Services.Jobs
|
||||||
private ICacheProvider Cache { get; }
|
private ICacheProvider Cache { get; }
|
||||||
private IJobRecord Job { get; }
|
private IJobRecord Job { get; }
|
||||||
private IRepository<PlexEpisodes> Repo { get; }
|
private IRepository<PlexEpisodes> Repo { get; }
|
||||||
|
private ISettingsService<ScheduledJobsSettings> Jobs { get; }
|
||||||
private const int ResultCount = 25;
|
private const int ResultCount = 25;
|
||||||
private const string PlexType = "episode";
|
private const string PlexType = "episode";
|
||||||
private const string TableName = "PlexEpisodes";
|
private const string TableName = "PlexEpisodes";
|
||||||
|
@ -142,6 +144,15 @@ namespace PlexRequests.Services.Jobs
|
||||||
{
|
{
|
||||||
try
|
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();
|
CacheEpisodes();
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
|
|
@ -290,26 +290,17 @@ namespace PlexRequests.Store.Repository
|
||||||
using (var db = Config.DbConnection())
|
using (var db = Config.DbConnection())
|
||||||
{
|
{
|
||||||
db.Open();
|
db.Open();
|
||||||
//using (var tran = db.BeginTransaction())
|
using (var tran = db.BeginTransaction())
|
||||||
//{
|
|
||||||
Log.Trace("Starting Transaction");
|
|
||||||
var result = enumerable.Sum(e => db.Insert(e));
|
|
||||||
var done = result == enumerable.Length;
|
|
||||||
|
|
||||||
Log.Trace($"Total Result: {done}");
|
|
||||||
Log.Trace($"db result: {result}");
|
|
||||||
Log.Trace($"totalitems result: {enumerable.Length}");
|
|
||||||
if (done)
|
|
||||||
{
|
{
|
||||||
Log.Trace("Commiting");
|
var result = enumerable.Sum(e => db.Insert(e));
|
||||||
//tran.Commit();
|
if (result != 0)
|
||||||
|
{
|
||||||
|
tran.Commit();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
Log.Trace("Rolling back the tran");
|
tran.Rollback();
|
||||||
|
|
||||||
//tran.Rollback();
|
|
||||||
return false;
|
return false;
|
||||||
//}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue