mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-31 03:50:08 -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 System.Threading.Tasks;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
@ -19,7 +20,7 @@ namespace Ombi.Core.Senders
|
||||||
{
|
{
|
||||||
public MovieSender(ISettingsService<RadarrSettings> radarrSettings, IRadarrApi api, ILogger<MovieSender> log,
|
public MovieSender(ISettingsService<RadarrSettings> radarrSettings, IRadarrApi api, ILogger<MovieSender> log,
|
||||||
ISettingsService<DogNzbSettings> dogSettings, IDogNzbApi dogApi, ISettingsService<CouchPotatoSettings> cpSettings,
|
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;
|
RadarrSettings = radarrSettings;
|
||||||
RadarrApi = api;
|
RadarrApi = api;
|
||||||
|
@ -29,6 +30,8 @@ namespace Ombi.Core.Senders
|
||||||
CouchPotatoSettings = cpSettings;
|
CouchPotatoSettings = cpSettings;
|
||||||
CouchPotatoApi = cpApi;
|
CouchPotatoApi = cpApi;
|
||||||
_userProfiles = userProfiles;
|
_userProfiles = userProfiles;
|
||||||
|
_requestQueuRepository = requestQueue;
|
||||||
|
_notificationHelper = notify;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ISettingsService<RadarrSettings> RadarrSettings { get; }
|
private ISettingsService<RadarrSettings> RadarrSettings { get; }
|
||||||
|
@ -39,9 +42,14 @@ namespace Ombi.Core.Senders
|
||||||
private ISettingsService<CouchPotatoSettings> CouchPotatoSettings { get; }
|
private ISettingsService<CouchPotatoSettings> CouchPotatoSettings { get; }
|
||||||
private ICouchPotatoApi CouchPotatoApi { get; }
|
private ICouchPotatoApi CouchPotatoApi { get; }
|
||||||
private readonly IRepository<UserQualityProfiles> _userProfiles;
|
private readonly IRepository<UserQualityProfiles> _userProfiles;
|
||||||
|
private readonly IRepository<RequestQueue> _requestQueuRepository;
|
||||||
|
private readonly INotificationHelper _notificationHelper;
|
||||||
|
|
||||||
public async Task<SenderResult> Send(MovieRequests model)
|
public async Task<SenderResult> Send(MovieRequests model)
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
var cpSettings = await CouchPotatoSettings.GetSettingsAsync();
|
var cpSettings = await CouchPotatoSettings.GetSettingsAsync();
|
||||||
//var watcherSettings = await WatcherSettings.GetSettingsAsync();
|
//var watcherSettings = await WatcherSettings.GetSettingsAsync();
|
||||||
var radarrSettings = await RadarrSettings.GetSettingsAsync();
|
var radarrSettings = await RadarrSettings.GetSettingsAsync();
|
||||||
|
@ -65,12 +73,20 @@ namespace Ombi.Core.Senders
|
||||||
{
|
{
|
||||||
return await SendToCp(model, cpSettings, cpSettings.DefaultProfileId);
|
return await SendToCp(model, cpSettings, cpSettings.DefaultProfileId);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
//if (watcherSettings.Enabled)
|
catch (Exception e)
|
||||||
//{
|
{
|
||||||
// return SendToWatcher(model, watcherSettings);
|
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
|
return new SenderResult
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,29 +1,42 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
using Ombi.Api.Lidarr;
|
using Ombi.Api.Lidarr;
|
||||||
using Ombi.Api.Lidarr.Models;
|
using Ombi.Api.Lidarr.Models;
|
||||||
using Ombi.Api.Radarr;
|
using Ombi.Api.Radarr;
|
||||||
using Ombi.Core.Settings;
|
using Ombi.Core.Settings;
|
||||||
using Ombi.Helpers;
|
using Ombi.Helpers;
|
||||||
using Ombi.Settings.Settings.Models.External;
|
using Ombi.Settings.Settings.Models.External;
|
||||||
|
using Ombi.Store.Entities;
|
||||||
using Ombi.Store.Entities.Requests;
|
using Ombi.Store.Entities.Requests;
|
||||||
|
using Ombi.Store.Repository;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
using ILogger = Microsoft.Extensions.Logging.ILogger;
|
||||||
|
|
||||||
namespace Ombi.Core.Senders
|
namespace Ombi.Core.Senders
|
||||||
{
|
{
|
||||||
public class MusicSender : IMusicSender
|
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;
|
_lidarrSettings = lidarr;
|
||||||
_lidarrApi = lidarrApi;
|
_lidarrApi = lidarrApi;
|
||||||
|
_log = log;
|
||||||
|
_requestQueueRepository = requestQueue;
|
||||||
|
_notificationHelper = notify;
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly ISettingsService<LidarrSettings> _lidarrSettings;
|
private readonly ISettingsService<LidarrSettings> _lidarrSettings;
|
||||||
private readonly ILidarrApi _lidarrApi;
|
private readonly ILidarrApi _lidarrApi;
|
||||||
|
private readonly ILogger _log;
|
||||||
|
private readonly IRepository<RequestQueue> _requestQueueRepository;
|
||||||
|
private readonly INotificationHelper _notificationHelper;
|
||||||
|
|
||||||
public async Task<SenderResult> Send(AlbumRequest model)
|
public async Task<SenderResult> Send(AlbumRequest model)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
var settings = await _lidarrSettings.GetSettingsAsync();
|
var settings = await _lidarrSettings.GetSettingsAsync();
|
||||||
if (settings.Enabled)
|
if (settings.Enabled)
|
||||||
|
@ -33,6 +46,23 @@ namespace Ombi.Core.Senders
|
||||||
|
|
||||||
return new SenderResult { Success = false, Sent = false, Message = "Lidarr is not enabled" };
|
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)
|
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,
|
public TvSender(ISonarrApi sonarrApi, ILogger<TvSender> log, ISettingsService<SonarrSettings> sonarrSettings,
|
||||||
ISettingsService<DogNzbSettings> dog, IDogNzbApi dogApi, ISettingsService<SickRageSettings> srSettings,
|
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;
|
SonarrApi = sonarrApi;
|
||||||
Logger = log;
|
Logger = log;
|
||||||
|
@ -33,6 +33,8 @@ namespace Ombi.Core.Senders
|
||||||
SickRageSettings = srSettings;
|
SickRageSettings = srSettings;
|
||||||
SickRageApi = srApi;
|
SickRageApi = srApi;
|
||||||
UserQualityProfiles = userProfiles;
|
UserQualityProfiles = userProfiles;
|
||||||
|
_requestQueueRepository = requestQueue;
|
||||||
|
_notificationHelper = notify;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ISonarrApi SonarrApi { get; }
|
private ISonarrApi SonarrApi { get; }
|
||||||
|
@ -43,9 +45,15 @@ namespace Ombi.Core.Senders
|
||||||
private ISettingsService<DogNzbSettings> DogNzbSettings { get; }
|
private ISettingsService<DogNzbSettings> DogNzbSettings { get; }
|
||||||
private ISettingsService<SickRageSettings> SickRageSettings { get; }
|
private ISettingsService<SickRageSettings> SickRageSettings { get; }
|
||||||
private IRepository<UserQualityProfiles> UserQualityProfiles { get; }
|
private IRepository<UserQualityProfiles> UserQualityProfiles { get; }
|
||||||
|
private readonly IRepository<RequestQueue> _requestQueueRepository;
|
||||||
|
private readonly INotificationHelper _notificationHelper;
|
||||||
|
|
||||||
public async Task<SenderResult> Send(ChildRequests model)
|
public async Task<SenderResult> Send(ChildRequests model)
|
||||||
{
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
var sonarr = await SonarrSettings.GetSettingsAsync();
|
var sonarr = await SonarrSettings.GetSettingsAsync();
|
||||||
if (sonarr.Enabled)
|
if (sonarr.Enabled)
|
||||||
{
|
{
|
||||||
|
@ -98,6 +106,26 @@ namespace Ombi.Core.Senders
|
||||||
Success = true
|
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)
|
private async Task<DogNzbAddResult> SendToDogNzb(ChildRequests model, DogNzbSettings settings)
|
||||||
{
|
{
|
||||||
|
|
|
@ -9,6 +9,8 @@ namespace Ombi.Store.Entities
|
||||||
public int RequestId { get; set; }
|
public int RequestId { get; set; }
|
||||||
public RequestType Type { get; set; }
|
public RequestType Type { get; set; }
|
||||||
public DateTime Dts { get; set; }
|
public DateTime Dts { get; set; }
|
||||||
|
public string Error { get; set; }
|
||||||
public DateTime Completed { get; set; }
|
public DateTime Completed { get; set; }
|
||||||
|
public int RetryCount { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue