From ba80dfe3aa0b5b5f61a188102a13c615ce790b03 Mon Sep 17 00:00:00 2001 From: "Jamie.Rees" Date: Thu, 29 Dec 2016 11:49:14 +0000 Subject: [PATCH] Finished #884 --- Ombi.Api/WatcherApi.cs | 12 +++++++--- Ombi.Services/Jobs/FaultQueueHandler.cs | 29 +++++++++++-------------- Ombi.Services/Jobs/WatcherCacher.cs | 4 ++-- Ombi.UI/Jobs/Scheduler.cs | 3 ++- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/Ombi.Api/WatcherApi.cs b/Ombi.Api/WatcherApi.cs index 5d1da833a..42ed12e2c 100644 --- a/Ombi.Api/WatcherApi.cs +++ b/Ombi.Api/WatcherApi.cs @@ -28,6 +28,7 @@ #endregion using System; +using System.Collections.Generic; using Newtonsoft.Json; using NLog; using Ombi.Api.Interfaces; @@ -73,7 +74,9 @@ namespace Ombi.Api { return new WatcherListStatusResultContainer(); } - return JsonConvert.DeserializeObject(response.Content); + var items = JsonConvert.DeserializeObject>(response.Content); + + return new WatcherListStatusResultContainer {Results = items}; } catch (Exception e) { @@ -95,7 +98,9 @@ namespace Ombi.Api { return new WatcherListStatusResultContainer(); } - return JsonConvert.DeserializeObject(response.Content); + var items = JsonConvert.DeserializeObject>(response.Content); + + return new WatcherListStatusResultContainer { Results = items }; } catch (Exception e) { @@ -114,9 +119,10 @@ namespace Ombi.Api RestRequest request; request = new RestRequest { - Resource = "/api" + Resource = string.IsNullOrEmpty(imdbid) ? "/api?apikey={apikey}&mode={mode}" : "/api?apikey={apikey}&mode={mode}&imdbid={imdbid}" }; + request.AddUrlSegment("apikey", apiKey); if (!string.IsNullOrEmpty(imdbid)) { diff --git a/Ombi.Services/Jobs/FaultQueueHandler.cs b/Ombi.Services/Jobs/FaultQueueHandler.cs index 7ec0183b0..61d3a4674 100644 --- a/Ombi.Services/Jobs/FaultQueueHandler.cs +++ b/Ombi.Services/Jobs/FaultQueueHandler.cs @@ -53,7 +53,7 @@ namespace Ombi.Services.Jobs ISickRageApi srApi, ISettingsService sonarrSettings, ISettingsService srSettings, ICouchPotatoApi cpApi, ISettingsService cpsettings, IRequestService requestService, ISettingsService hpSettings, IHeadphonesApi headphonesApi, ISettingsService prSettings, - ISecurityExtensions security) + ISecurityExtensions security, IMovieSender movieSender) { Record = record; Repo = repo; @@ -70,8 +70,10 @@ namespace Ombi.Services.Jobs HeadphoneSettings = hpSettings; Security = security; PrSettings = prSettings.GetSettings(); + MovieSender = movieSender; } + private IMovieSender MovieSender { get; } private IRepository Repo { get; } private IJobRecord Record { get; } private ISonarrApi SonarrApi { get; } @@ -197,24 +199,19 @@ namespace Ombi.Services.Jobs } } - private bool ProcessMovies(RequestedModel model, CouchPotatoSettings cp) + private bool ProcessMovies(RequestedModel model) { try { - if (cp.Enabled) + var result = MovieSender.Send(model).Result; + if (result.Result) { - var result = CpApi.AddMovie(model.ImdbId, cp.ApiKey, model.Title, - cp.FullUri, cp.ProfileId); - - if (result) - { - // Approve it now - model.Approved = true; - RequestService.UpdateRequest(model); - }; - - return result; - } + // Approve it now + model.Approved = true; + RequestService.UpdateRequest(model); + return true; + }; + return false; } catch (Exception e) @@ -272,7 +269,7 @@ namespace Ombi.Services.Jobs switch (request.Type) { case RequestType.Movie: - result = ProcessMovies(model, cpSettings); + result = ProcessMovies(model); break; case RequestType.TvShow: result = ProcessTvShow(model, sonarrSettings, sickrageSettings); diff --git a/Ombi.Services/Jobs/WatcherCacher.cs b/Ombi.Services/Jobs/WatcherCacher.cs index e25784040..6e172f6df 100644 --- a/Ombi.Services/Jobs/WatcherCacher.cs +++ b/Ombi.Services/Jobs/WatcherCacher.cs @@ -47,7 +47,7 @@ namespace Ombi.Services.Jobs IWatcherApi watcherApi, ICacheProvider cache, IJobRecord rec) { WatcherSettings = watcher; - WatcherApi = WatcherApi; + WatcherApi = watcherApi; Cache = cache; Job = rec; } @@ -80,7 +80,7 @@ namespace Ombi.Services.Jobs movies?.Results?.Where(x => x.status.Equals("Wanted", StringComparison.CurrentCultureIgnoreCase)); if (wantedMovies != null && wantedMovies.Any()) { - Cache.Set(CacheKeys.WatcherQueued, movies.Results.Select(x => x.imdbid), CacheKeys.TimeFrameMinutes.SchedulerCaching); + Cache.Set(CacheKeys.WatcherQueued, movies.Results.Select(x => x.imdbid).ToArray(), CacheKeys.TimeFrameMinutes.SchedulerCaching); } } diff --git a/Ombi.UI/Jobs/Scheduler.cs b/Ombi.UI/Jobs/Scheduler.cs index 641d32a15..70055fd5b 100644 --- a/Ombi.UI/Jobs/Scheduler.cs +++ b/Ombi.UI/Jobs/Scheduler.cs @@ -217,7 +217,8 @@ namespace Ombi.UI.Jobs var watcherCacher = TriggerBuilder.Create() .WithIdentity("WatcherCacher", "Cache") - .StartAt(DateBuilder.FutureDate(4, IntervalUnit.Minute)) + //.StartNow() + .StartAt(DateBuilder.FutureDate(3, IntervalUnit.Minute)) .WithSimpleSchedule(x => x.WithIntervalInMinutes(s.WatcherCacher).RepeatForever()) .Build();