mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-11 15:56:05 -07:00
Finished the queue #483
This commit is contained in:
parent
50dec5f530
commit
dd92bb179c
6 changed files with 105 additions and 32 deletions
|
@ -24,18 +24,16 @@
|
||||||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
// ************************************************************************/
|
// ************************************************************************/
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
using NLog;
|
using NLog;
|
||||||
|
|
||||||
using PlexRequests.Api.Interfaces;
|
using PlexRequests.Api.Interfaces;
|
||||||
using PlexRequests.Core;
|
|
||||||
using PlexRequests.Core.SettingModels;
|
using PlexRequests.Core.SettingModels;
|
||||||
using PlexRequests.Store;
|
using PlexRequests.Store;
|
||||||
|
|
||||||
namespace PlexRequests.UI.Helpers
|
namespace PlexRequests.Core
|
||||||
{
|
{
|
||||||
public class HeadphonesSender
|
public class HeadphonesSender
|
||||||
{
|
{
|
|
@ -90,6 +90,7 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="CacheKeys.cs" />
|
<Compile Include="CacheKeys.cs" />
|
||||||
|
<Compile Include="HeadphonesSender.cs" />
|
||||||
<Compile Include="IPlexReadOnlyDatabase.cs" />
|
<Compile Include="IPlexReadOnlyDatabase.cs" />
|
||||||
<Compile Include="IStatusChecker.cs" />
|
<Compile Include="IStatusChecker.cs" />
|
||||||
<Compile Include="Notification\NotificationMessage.cs" />
|
<Compile Include="Notification\NotificationMessage.cs" />
|
||||||
|
|
|
@ -51,24 +51,36 @@ namespace PlexRequests.Services.Jobs
|
||||||
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
|
private static readonly Logger Log = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
public FaultQueueHandler(IJobRecord record, IRepository<RequestQueue> repo, ISonarrApi sonarrApi,
|
public FaultQueueHandler(IJobRecord record, IRepository<RequestQueue> repo, ISonarrApi sonarrApi,
|
||||||
ISickRageApi srApi,
|
ISickRageApi srApi, ISettingsService<SonarrSettings> sonarrSettings, ISettingsService<SickRageSettings> srSettings,
|
||||||
ISettingsService<SonarrSettings> sonarrSettings, ISettingsService<SickRageSettings> srSettings)
|
ICouchPotatoApi cpApi, ISettingsService<CouchPotatoSettings> cpsettings, IRequestService requestService,
|
||||||
|
ISettingsService<HeadphonesSettings> hpSettings, IHeadphonesApi headphonesApi)
|
||||||
{
|
{
|
||||||
Record = record;
|
Record = record;
|
||||||
Repo = repo;
|
Repo = repo;
|
||||||
SonarrApi = sonarrApi;
|
SonarrApi = sonarrApi;
|
||||||
SrApi = srApi;
|
SrApi = srApi;
|
||||||
|
CpApi = cpApi;
|
||||||
|
HpApi = headphonesApi;
|
||||||
|
|
||||||
|
RequestService = requestService;
|
||||||
|
|
||||||
SickrageSettings = srSettings;
|
SickrageSettings = srSettings;
|
||||||
SonarrSettings = sonarrSettings;
|
SonarrSettings = sonarrSettings;
|
||||||
|
CpSettings = cpsettings;
|
||||||
|
HeadphoneSettings = hpSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IRepository<RequestQueue> Repo { get; }
|
private IRepository<RequestQueue> Repo { get; }
|
||||||
private IJobRecord Record { get; }
|
private IJobRecord Record { get; }
|
||||||
private ISonarrApi SonarrApi { get; }
|
private ISonarrApi SonarrApi { get; }
|
||||||
private ISickRageApi SrApi { get; }
|
private ISickRageApi SrApi { get; }
|
||||||
private ISettingsService<SonarrSettings> SonarrSettings { get; set; }
|
private ICouchPotatoApi CpApi { get; }
|
||||||
private ISettingsService<SickRageSettings> SickrageSettings { get; set; }
|
private IHeadphonesApi HpApi { get; }
|
||||||
|
private IRequestService RequestService { get; }
|
||||||
|
private ISettingsService<SonarrSettings> SonarrSettings { get; }
|
||||||
|
private ISettingsService<SickRageSettings> SickrageSettings { get; }
|
||||||
|
private ISettingsService<CouchPotatoSettings> CpSettings { get; }
|
||||||
|
private ISettingsService<HeadphonesSettings> HeadphoneSettings { get; }
|
||||||
|
|
||||||
public void Execute(IJobExecutionContext context)
|
public void Execute(IJobExecutionContext context)
|
||||||
{
|
{
|
||||||
|
@ -76,7 +88,6 @@ namespace PlexRequests.Services.Jobs
|
||||||
{
|
{
|
||||||
var faultedRequests = Repo.GetAll().ToList();
|
var faultedRequests = Repo.GetAll().ToList();
|
||||||
|
|
||||||
|
|
||||||
var missingInfo = faultedRequests.Where(x => x.FaultType == FaultType.MissingInformation).ToList();
|
var missingInfo = faultedRequests.Where(x => x.FaultType == FaultType.MissingInformation).ToList();
|
||||||
ProcessMissingInformation(missingInfo);
|
ProcessMissingInformation(missingInfo);
|
||||||
|
|
||||||
|
@ -90,7 +101,7 @@ namespace PlexRequests.Services.Jobs
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
Record.Record(JobNames.RequestLimitReset);
|
Record.Record(JobNames.FaultQueueHandler);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,9 +174,66 @@ namespace PlexRequests.Services.Jobs
|
||||||
// Couldn't send it
|
// Couldn't send it
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Approve it
|
||||||
|
tvModel.Approved = true;
|
||||||
|
RequestService.UpdateRequest(tvModel);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Log.Error(e);
|
||||||
|
return false; // It fails so it will get added back into the queue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool ProcessMovies(RequestedModel model, CouchPotatoSettings cp)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (cp.Enabled)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Log.Error(e);
|
||||||
|
return false; // It fails so it will get added back into the queue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool ProcessAlbums(RequestedModel model, HeadphonesSettings hp)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (hp.Enabled)
|
||||||
|
{
|
||||||
|
var sender = new HeadphonesSender(HpApi, hp, RequestService);
|
||||||
|
var result = sender.AddAlbum(model).Result;
|
||||||
|
|
||||||
|
if (result)
|
||||||
|
{
|
||||||
|
// Approve it now
|
||||||
|
model.Approved = true;
|
||||||
|
RequestService.UpdateRequest(model);
|
||||||
|
};
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
|
@ -179,36 +247,45 @@ namespace PlexRequests.Services.Jobs
|
||||||
{
|
{
|
||||||
var sonarrSettings = SonarrSettings.GetSettings();
|
var sonarrSettings = SonarrSettings.GetSettings();
|
||||||
var sickrageSettings = SickrageSettings.GetSettings();
|
var sickrageSettings = SickrageSettings.GetSettings();
|
||||||
|
var cpSettings = CpSettings.GetSettings();
|
||||||
|
var hpSettings = HeadphoneSettings.GetSettings();
|
||||||
|
|
||||||
if (!requests.Any())
|
if (!requests.Any())
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var tv = requests.Where(x => x.Type == RequestType.TvShow);
|
|
||||||
var movie = requests.Where(x => x.Type == RequestType.Movie);
|
|
||||||
var album = requests.Where(x => x.Type == RequestType.Album);
|
|
||||||
|
|
||||||
|
foreach (var request in requests)
|
||||||
|
|
||||||
foreach (var t in tv)
|
|
||||||
{
|
{
|
||||||
var tvModel = ByteConverterHelper.ReturnObject<RequestedModel>(t.Content);
|
var model = ByteConverterHelper.ReturnObject<RequestedModel>(request.Content);
|
||||||
var result = ProcessTvShow(tvModel, sonarrSettings, sickrageSettings);
|
var result = false;
|
||||||
|
switch (request.Type)
|
||||||
|
{
|
||||||
|
case RequestType.Movie:
|
||||||
|
result = ProcessMovies(model, cpSettings);
|
||||||
|
break;
|
||||||
|
case RequestType.TvShow:
|
||||||
|
result = ProcessTvShow(model, sonarrSettings, sickrageSettings);
|
||||||
|
break;
|
||||||
|
case RequestType.Album:
|
||||||
|
result = ProcessAlbums(model, hpSettings);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new ArgumentOutOfRangeException();
|
||||||
|
}
|
||||||
|
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
// we now have the info but couldn't add it, so do nothing now.
|
// we now have the info but couldn't add it, so do nothing now.
|
||||||
t.LastRetry = DateTime.UtcNow;
|
request.LastRetry = DateTime.UtcNow;
|
||||||
Repo.Update(t);
|
Repo.Update(request);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Successful, remove from the fault queue
|
// Successful, remove from the fault queue
|
||||||
Repo.Delete(t);
|
Repo.Delete(request);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -37,5 +37,6 @@ namespace PlexRequests.Services.Jobs
|
||||||
public const string RequestLimitReset = "Request Limit Reset";
|
public const string RequestLimitReset = "Request Limit Reset";
|
||||||
public const string EpisodeCacher = "Plex Episode Cacher";
|
public const string EpisodeCacher = "Plex Episode Cacher";
|
||||||
public const string RecentlyAddedEmail = "Recently Added Email Notification";
|
public const string RecentlyAddedEmail = "Recently Added Email Notification";
|
||||||
|
public const string FaultQueueHandler = "Request Fault Queue Handler";
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -909,9 +909,7 @@ namespace PlexRequests.UI.Modules
|
||||||
var result = sender.SendToSickRage(srSettings, model);
|
var result = sender.SendToSickRage(srSettings, model);
|
||||||
if (result?.result == "success")
|
if (result?.result == "success")
|
||||||
{
|
{
|
||||||
return
|
return await AddRequest(model, settings,
|
||||||
await
|
|
||||||
AddRequest(model, settings,
|
|
||||||
$"{fullShowName} {Resources.UI.Search_SuccessfullyAdded}");
|
$"{fullShowName} {Resources.UI.Search_SuccessfullyAdded}");
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
@ -924,8 +922,7 @@ namespace PlexRequests.UI.Modules
|
||||||
|
|
||||||
if (!srSettings.Enabled && !s.Enabled)
|
if (!srSettings.Enabled && !s.Enabled)
|
||||||
{
|
{
|
||||||
return
|
return await AddRequest(model, settings, $"{fullShowName} {Resources.UI.Search_SuccessfullyAdded}");
|
||||||
await AddRequest(model, settings, $"{fullShowName} {Resources.UI.Search_SuccessfullyAdded}");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
|
@ -1102,7 +1099,7 @@ namespace PlexRequests.UI.Modules
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Log.Error(e);
|
Log.Error(e);
|
||||||
await FaultQueue.QueueItemAsync(model, albumInfo.id, RequestType.Movie, FaultType.RequestFault);
|
await FaultQueue.QueueItemAsync(model, albumInfo.id, RequestType.Album, FaultType.RequestFault);
|
||||||
|
|
||||||
await NotificationService.Publish(new NotificationModel
|
await NotificationService.Publish(new NotificationModel
|
||||||
{
|
{
|
||||||
|
|
|
@ -210,7 +210,6 @@
|
||||||
<Compile Include="Helpers\CustomHtmlHelper.cs" />
|
<Compile Include="Helpers\CustomHtmlHelper.cs" />
|
||||||
<Compile Include="Helpers\DebugRootPathProvider.cs" />
|
<Compile Include="Helpers\DebugRootPathProvider.cs" />
|
||||||
<Compile Include="Helpers\EmptyViewBase.cs" />
|
<Compile Include="Helpers\EmptyViewBase.cs" />
|
||||||
<Compile Include="Helpers\HeadphonesSender.cs" />
|
|
||||||
<Compile Include="Helpers\AngularViewBase.cs" />
|
<Compile Include="Helpers\AngularViewBase.cs" />
|
||||||
<Compile Include="Helpers\HtmlSecurityHelper.cs" />
|
<Compile Include="Helpers\HtmlSecurityHelper.cs" />
|
||||||
<Compile Include="Helpers\SecurityExtensions.cs" />
|
<Compile Include="Helpers\SecurityExtensions.cs" />
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue