mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-30 03:28:28 -07:00
Save to the request queue !wip
This commit is contained in:
parent
b1e6fd313b
commit
207fbe0a8f
4 changed files with 110 additions and 34 deletions
|
@ -1,4 +1,5 @@
|
|||
using System.Linq;
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
@ -19,7 +20,7 @@ namespace Ombi.Core.Senders
|
|||
{
|
||||
public MovieSender(ISettingsService<RadarrSettings> radarrSettings, IRadarrApi api, ILogger<MovieSender> log,
|
||||
ISettingsService<DogNzbSettings> dogSettings, IDogNzbApi dogApi, ISettingsService<CouchPotatoSettings> cpSettings,
|
||||
ICouchPotatoApi cpApi, IRepository<UserQualityProfiles> userProfiles)
|
||||
ICouchPotatoApi cpApi, IRepository<UserQualityProfiles> userProfiles, IRepository<RequestQueue> requestQueue, INotificationHelper notify)
|
||||
{
|
||||
RadarrSettings = radarrSettings;
|
||||
RadarrApi = api;
|
||||
|
@ -29,6 +30,8 @@ namespace Ombi.Core.Senders
|
|||
CouchPotatoSettings = cpSettings;
|
||||
CouchPotatoApi = cpApi;
|
||||
_userProfiles = userProfiles;
|
||||
_requestQueuRepository = requestQueue;
|
||||
_notificationHelper = notify;
|
||||
}
|
||||
|
||||
private ISettingsService<RadarrSettings> RadarrSettings { get; }
|
||||
|
@ -39,9 +42,14 @@ namespace Ombi.Core.Senders
|
|||
private ISettingsService<CouchPotatoSettings> CouchPotatoSettings { get; }
|
||||
private ICouchPotatoApi CouchPotatoApi { get; }
|
||||
private readonly IRepository<UserQualityProfiles> _userProfiles;
|
||||
private readonly IRepository<RequestQueue> _requestQueuRepository;
|
||||
private readonly INotificationHelper _notificationHelper;
|
||||
|
||||
public async Task<SenderResult> Send(MovieRequests model)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
var cpSettings = await CouchPotatoSettings.GetSettingsAsync();
|
||||
//var watcherSettings = await WatcherSettings.GetSettingsAsync();
|
||||
var radarrSettings = await RadarrSettings.GetSettingsAsync();
|
||||
|
@ -65,12 +73,20 @@ namespace Ombi.Core.Senders
|
|||
{
|
||||
return await SendToCp(model, cpSettings, cpSettings.DefaultProfileId);
|
||||
}
|
||||
|
||||
//if (watcherSettings.Enabled)
|
||||
//{
|
||||
// return SendToWatcher(model, watcherSettings);
|
||||
//}
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.LogError(e, "Error when seing movie to DVR app, added to the request queue"S);
|
||||
await _requestQueuRepository.Add(new RequestQueue
|
||||
{
|
||||
Dts = DateTime.UtcNow,
|
||||
Error = e.Message,
|
||||
RequestId = model.Id,
|
||||
Type = RequestType.Movie,
|
||||
RetryCount = 0
|
||||
});
|
||||
_notificationHelper.Notify(model, NotificationType.ItemAddedToFaultQueue);
|
||||
}
|
||||
|
||||
return new SenderResult
|
||||
{
|
||||
|
@ -150,7 +166,7 @@ namespace Ombi.Core.Senders
|
|||
// Search for it
|
||||
if (!settings.AddOnly)
|
||||
{
|
||||
await RadarrApi.MovieSearch(new[] {existingMovie.id}, settings.ApiKey, settings.FullUri);
|
||||
await RadarrApi.MovieSearch(new[] { existingMovie.id }, settings.ApiKey, settings.FullUri);
|
||||
}
|
||||
|
||||
return new SenderResult { Success = true, Sent = true };
|
||||
|
|
|
@ -1,29 +1,42 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Ombi.Api.Lidarr;
|
||||
using Ombi.Api.Lidarr.Models;
|
||||
using Ombi.Api.Radarr;
|
||||
using Ombi.Core.Settings;
|
||||
using Ombi.Helpers;
|
||||
using Ombi.Settings.Settings.Models.External;
|
||||
using Ombi.Store.Entities;
|
||||
using Ombi.Store.Entities.Requests;
|
||||
using Ombi.Store.Repository;
|
||||
using Serilog;
|
||||
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
||||
|
||||
namespace Ombi.Core.Senders
|
||||
{
|
||||
public class MusicSender : IMusicSender
|
||||
{
|
||||
public MusicSender(ISettingsService<LidarrSettings> lidarr, ILidarrApi lidarrApi)
|
||||
public MusicSender(ISettingsService<LidarrSettings> lidarr, ILidarrApi lidarrApi, ILogger<MusicSender> log,
|
||||
IRepository<RequestQueue> requestQueue, INotificationHelper notify)
|
||||
{
|
||||
_lidarrSettings = lidarr;
|
||||
_lidarrApi = lidarrApi;
|
||||
_log = log;
|
||||
_requestQueueRepository = requestQueue;
|
||||
_notificationHelper = notify;
|
||||
}
|
||||
|
||||
private readonly ISettingsService<LidarrSettings> _lidarrSettings;
|
||||
private readonly ILidarrApi _lidarrApi;
|
||||
private readonly ILogger _log;
|
||||
private readonly IRepository<RequestQueue> _requestQueueRepository;
|
||||
private readonly INotificationHelper _notificationHelper;
|
||||
|
||||
public async Task<SenderResult> Send(AlbumRequest model)
|
||||
{
|
||||
try
|
||||
{
|
||||
var settings = await _lidarrSettings.GetSettingsAsync();
|
||||
if (settings.Enabled)
|
||||
|
@ -33,6 +46,23 @@ namespace Ombi.Core.Senders
|
|||
|
||||
return new SenderResult { Success = false, Sent = false, Message = "Lidarr is not enabled" };
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_log.LogError(e, "Exception thrown when sending a music to DVR app, added to the request queue");
|
||||
await _requestQueueRepository.Add(new RequestQueue
|
||||
{
|
||||
Dts = DateTime.UtcNow,
|
||||
Error = e.Message,
|
||||
RequestId = model.Id,
|
||||
Type = RequestType.Album,
|
||||
RetryCount = 0
|
||||
});
|
||||
_notificationHelper.Notify(model, NotificationType.ItemAddedToFaultQueue);
|
||||
}
|
||||
|
||||
|
||||
return new SenderResult { Success = false, Sent = false, Message = "Something went wrong!" };
|
||||
}
|
||||
|
||||
private async Task<SenderResult> SendToLidarr(AlbumRequest model, LidarrSettings settings)
|
||||
{
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace Ombi.Core.Senders
|
|||
{
|
||||
public TvSender(ISonarrApi sonarrApi, ILogger<TvSender> log, ISettingsService<SonarrSettings> sonarrSettings,
|
||||
ISettingsService<DogNzbSettings> dog, IDogNzbApi dogApi, ISettingsService<SickRageSettings> srSettings,
|
||||
ISickRageApi srApi, IRepository<UserQualityProfiles> userProfiles)
|
||||
ISickRageApi srApi, IRepository<UserQualityProfiles> userProfiles, IRepository<RequestQueue> requestQueue, INotificationHelper notify)
|
||||
{
|
||||
SonarrApi = sonarrApi;
|
||||
Logger = log;
|
||||
|
@ -33,6 +33,8 @@ namespace Ombi.Core.Senders
|
|||
SickRageSettings = srSettings;
|
||||
SickRageApi = srApi;
|
||||
UserQualityProfiles = userProfiles;
|
||||
_requestQueueRepository = requestQueue;
|
||||
_notificationHelper = notify;
|
||||
}
|
||||
|
||||
private ISonarrApi SonarrApi { get; }
|
||||
|
@ -43,9 +45,15 @@ namespace Ombi.Core.Senders
|
|||
private ISettingsService<DogNzbSettings> DogNzbSettings { get; }
|
||||
private ISettingsService<SickRageSettings> SickRageSettings { get; }
|
||||
private IRepository<UserQualityProfiles> UserQualityProfiles { get; }
|
||||
private readonly IRepository<RequestQueue> _requestQueueRepository;
|
||||
private readonly INotificationHelper _notificationHelper;
|
||||
|
||||
public async Task<SenderResult> Send(ChildRequests model)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
var sonarr = await SonarrSettings.GetSettingsAsync();
|
||||
if (sonarr.Enabled)
|
||||
{
|
||||
|
@ -98,6 +106,26 @@ namespace Ombi.Core.Senders
|
|||
Success = true
|
||||
};
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Logger.LogError(e, "Exception thrown when sending a movie to DVR app, added to the request queue");
|
||||
await _requestQueueRepository.Add(new RequestQueue
|
||||
{
|
||||
Dts = DateTime.UtcNow,
|
||||
Error = e.Message,
|
||||
RequestId = model.Id,
|
||||
Type = RequestType.TvShow,
|
||||
RetryCount = 0
|
||||
});
|
||||
_notificationHelper.Notify(model, NotificationType.ItemAddedToFaultQueue);
|
||||
}
|
||||
|
||||
return new SenderResult
|
||||
{
|
||||
Success = false,
|
||||
Message = "Something wen't wrong!"
|
||||
};
|
||||
}
|
||||
|
||||
private async Task<DogNzbAddResult> SendToDogNzb(ChildRequests model, DogNzbSettings settings)
|
||||
{
|
||||
|
|
|
@ -9,6 +9,8 @@ namespace Ombi.Store.Entities
|
|||
public int RequestId { get; set; }
|
||||
public RequestType Type { get; set; }
|
||||
public DateTime Dts { get; set; }
|
||||
public string Error { get; set; }
|
||||
public DateTime Completed { get; set; }
|
||||
public int RetryCount { get; set; }
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue