From ba06e8630f4bf4db8f751ad5407ce47b62f77c00 Mon Sep 17 00:00:00 2001 From: Drewster727 Date: Thu, 21 Apr 2016 09:00:06 -0500 Subject: [PATCH] additional cacher error handling + don't bother checking the requests when we don't get data back from plex --- .../Jobs/CouchPotatoCacher.cs | 13 ++++-- .../Jobs/PlexAvailabilityChecker.cs | 41 +++++++++++++------ PlexRequests.Services/Jobs/SickRageCacher.cs | 13 ++++-- PlexRequests.Services/Jobs/SonarrCacher.cs | 13 ++++-- 4 files changed, 58 insertions(+), 22 deletions(-) diff --git a/PlexRequests.Services/Jobs/CouchPotatoCacher.cs b/PlexRequests.Services/Jobs/CouchPotatoCacher.cs index 2440477f0..d31bb7aa4 100644 --- a/PlexRequests.Services/Jobs/CouchPotatoCacher.cs +++ b/PlexRequests.Services/Jobs/CouchPotatoCacher.cs @@ -62,10 +62,17 @@ namespace PlexRequests.Services.Jobs if (settings.Enabled) { Log.Trace("Getting all movies from CouchPotato"); - var movies = CpApi.GetMovies(settings.FullUri, settings.ApiKey, new[] { "active" }); - if (movies != null) + try { - Cache.Set(CacheKeys.CouchPotatoQueued, movies, CacheKeys.TimeFrameMinutes.SchedulerCaching); + var movies = CpApi.GetMovies(settings.FullUri, settings.ApiKey, new[] { "active" }); + if (movies != null) + { + Cache.Set(CacheKeys.CouchPotatoQueued, movies, CacheKeys.TimeFrameMinutes.SchedulerCaching); + } + } + catch (System.Exception ex) + { + Log.Error(ex, "Failed caching queued items from CouchPotato"); } } } diff --git a/PlexRequests.Services/Jobs/PlexAvailabilityChecker.cs b/PlexRequests.Services/Jobs/PlexAvailabilityChecker.cs index 3c7915fa6..b47651123 100644 --- a/PlexRequests.Services/Jobs/PlexAvailabilityChecker.cs +++ b/PlexRequests.Services/Jobs/PlexAvailabilityChecker.cs @@ -75,6 +75,13 @@ namespace PlexRequests.Services.Jobs } var libraries = CachedLibraries(authSettings, plexSettings, true); //force setting the cache (10 min intervals via scheduler) + + if (libraries == null || !libraries.Any()) + { + Log.Info("Did not find any libraries in Plex."); + return; + } + var movies = GetPlexMovies().ToArray(); var shows = GetPlexTvShows().ToArray(); var albums = GetPlexAlbums().ToArray(); @@ -248,25 +255,33 @@ namespace PlexRequests.Services.Jobs return results; // don't error out here, just let it go! } - if (setCache) + try { - Log.Trace("Plex Lib API Call"); - results = GetLibraries(authSettings, plexSettings); + if (setCache) + { + Log.Trace("Plex Lib API Call"); + results = GetLibraries(authSettings, plexSettings); - Log.Trace("Plex Lib Cache Set Call"); - if (results != null) + Log.Trace("Plex Lib Cache Set Call"); + if (results != null) + { + Cache.Set(CacheKeys.PlexLibaries, results, CacheKeys.TimeFrameMinutes.SchedulerCaching); + } + } + else { - Cache.Set(CacheKeys.PlexLibaries, results, CacheKeys.TimeFrameMinutes.SchedulerCaching); + Log.Trace("Plex Lib GetSet Call"); + results = Cache.GetOrSet(CacheKeys.PlexLibaries, () => { + Log.Trace("Plex Lib API Call (inside getset)"); + return GetLibraries(authSettings, plexSettings); + }, CacheKeys.TimeFrameMinutes.SchedulerCaching); } - } - else + } + catch (Exception ex) { - Log.Trace("Plex Lib GetSet Call"); - results = Cache.GetOrSet(CacheKeys.PlexLibaries, () => { - Log.Trace("Plex Lib API Call (inside getset)"); - return GetLibraries(authSettings, plexSettings); - }, CacheKeys.TimeFrameMinutes.SchedulerCaching); + Log.Error(ex, "Failed to obtain Plex libraries"); } + return results; } diff --git a/PlexRequests.Services/Jobs/SickRageCacher.cs b/PlexRequests.Services/Jobs/SickRageCacher.cs index 1a28956a5..3591cf7bb 100644 --- a/PlexRequests.Services/Jobs/SickRageCacher.cs +++ b/PlexRequests.Services/Jobs/SickRageCacher.cs @@ -62,10 +62,17 @@ namespace PlexRequests.Services.Jobs if (settings.Enabled) { Log.Trace("Getting all shows from SickRage"); - var shows = SrApi.GetShows(settings.ApiKey, settings.FullUri); - if (shows != null) + try { - Cache.Set(CacheKeys.SickRageQueued, shows.Result, CacheKeys.TimeFrameMinutes.SchedulerCaching); + var shows = SrApi.GetShows(settings.ApiKey, settings.FullUri); + if (shows != null) + { + Cache.Set(CacheKeys.SickRageQueued, shows.Result, CacheKeys.TimeFrameMinutes.SchedulerCaching); + } + } + catch (System.Exception ex) + { + Log.Error(ex, "Failed caching queued items from SickRage"); } } } diff --git a/PlexRequests.Services/Jobs/SonarrCacher.cs b/PlexRequests.Services/Jobs/SonarrCacher.cs index 983a50eea..15aef545d 100644 --- a/PlexRequests.Services/Jobs/SonarrCacher.cs +++ b/PlexRequests.Services/Jobs/SonarrCacher.cs @@ -63,10 +63,17 @@ namespace PlexRequests.Services.Jobs if (settings.Enabled) { Log.Trace("Getting all tv series from Sonarr"); - var series = SonarrApi.GetSeries(settings.ApiKey, settings.FullUri); - if (series != null) + try { - Cache.Set(CacheKeys.SonarrQueued, series, CacheKeys.TimeFrameMinutes.SchedulerCaching); + var series = SonarrApi.GetSeries(settings.ApiKey, settings.FullUri); + if (series != null) + { + Cache.Set(CacheKeys.SonarrQueued, series, CacheKeys.TimeFrameMinutes.SchedulerCaching); + } + } + catch (System.Exception ex) + { + Log.Error(ex, "Failed caching queued items from Sonarr"); } } }