From 47f323fcdd0740bf1a0aedceedd8b38265bf6377 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Thu, 7 Nov 2019 15:51:19 +0000 Subject: [PATCH 01/11] Fixed an error with the newsletter with the new db structure --- src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs b/src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs index 7c056e577..503410d82 100644 --- a/src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs +++ b/src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs @@ -37,7 +37,7 @@ namespace Ombi.Schedule.Jobs.Ombi IMovieDbApi movieApi, ITvMazeApi tvApi, IEmailProvider email, ISettingsService custom, ISettingsService emailSettings, INotificationTemplatesRepository templateRepo, UserManager um, ISettingsService newsletter, ILogger log, - ILidarrApi lidarrApi, IRepository albumCache, ISettingsService lidarrSettings, + ILidarrApi lidarrApi, IExternalRepository albumCache, ISettingsService lidarrSettings, ISettingsService ombiSettings, ISettingsService plexSettings, ISettingsService embySettings) { _plex = plex; @@ -66,7 +66,7 @@ namespace Ombi.Schedule.Jobs.Ombi private readonly IPlexContentRepository _plex; private readonly IEmbyContentRepository _emby; - private readonly IRepository _recentlyAddedLog; + private readonly IExternalRepository _recentlyAddedLog; private readonly IMovieDbApi _movieApi; private readonly ITvMazeApi _tvApi; private readonly IEmailProvider _email; From 96e3e88261970441fc64144ec3c3dfd7cba02b2a Mon Sep 17 00:00:00 2001 From: tidusjar Date: Thu, 7 Nov 2019 22:22:53 +0000 Subject: [PATCH 02/11] Fixed the issues where the DB was being disposed too early --- src/Ombi.Core/Engine/MovieRequestEngine.cs | 51 +++++++-------- src/Ombi.Core/Engine/TvRequestEngine.cs | 65 ++++++++++--------- .../Jobs/Emby/EmbyAvaliabilityChecker.cs | 1 - .../Jobs/Emby/EmbyContentSync.cs | 1 - .../Jobs/Emby/EmbyEpisodeSync.cs | 1 - .../Jobs/Ombi/Interfaces/IssuesPurge.cs | 1 - .../Jobs/Ombi/MediaDatabaseRefresh.cs | 1 - src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs | 7 +- .../Jobs/Ombi/RefreshMetadata.cs | 2 - .../Jobs/Plex/PlexAvailabilityChecker.cs | 2 - .../Jobs/Plex/PlexContentSync.cs | 1 - .../Jobs/Plex/PlexEpisodeSync.cs | 1 - .../Context/MySql/OmbiMySqlContext.cs | 5 ++ src/Ombi.Store/Repository/BaseRepository.cs | 34 +++++----- .../Repository/IExternalRepository.cs | 2 +- src/Ombi.Store/Repository/IRepository.cs | 2 +- 16 files changed, 86 insertions(+), 91 deletions(-) diff --git a/src/Ombi.Core/Engine/MovieRequestEngine.cs b/src/Ombi.Core/Engine/MovieRequestEngine.cs index 456ba267a..51a1c14db 100644 --- a/src/Ombi.Core/Engine/MovieRequestEngine.cs +++ b/src/Ombi.Core/Engine/MovieRequestEngine.cs @@ -188,11 +188,7 @@ namespace Ombi.Core.Engine var requests = await (OrderMovies(allRequests, orderFilter.OrderType)).Skip(position).Take(count) .ToListAsync(); - requests.ForEach(async x => - { - x.PosterPath = PosterPathHelper.FixPosterPath(x.PosterPath); - await CheckForSubscription(shouldHide, x); - }); + await CheckForSubscription(shouldHide, requests); return new RequestsViewModel { Collection = requests, @@ -251,26 +247,30 @@ namespace Ombi.Core.Engine allRequests = await MovieRepository.GetWithUser().ToListAsync(); } - allRequests.ForEach(async x => - { - x.PosterPath = PosterPathHelper.FixPosterPath(x.PosterPath); - await CheckForSubscription(shouldHide, x); - }); + await CheckForSubscription(shouldHide, allRequests); + return allRequests; } - private async Task CheckForSubscription(HideResult shouldHide, MovieRequests x) + private async Task CheckForSubscription(HideResult shouldHide, List movieRequests) { - if (shouldHide.UserId == x.RequestedUserId) + var requestIds = movieRequests.Select(x => x.Id); + var sub = await _subscriptionRepository.GetAll().Where(s => + s.UserId == shouldHide.UserId && requestIds.Contains(s.RequestId) && s.RequestType == RequestType.Movie) + .ToListAsync(); + foreach (var x in movieRequests) { - x.ShowSubscribe = false; - } - else - { - x.ShowSubscribe = true; - var sub = await _subscriptionRepository.GetAll().FirstOrDefaultAsync(s => - s.UserId == shouldHide.UserId && s.RequestId == x.Id && s.RequestType == RequestType.Movie); - x.Subscribed = sub != null; + x.PosterPath = PosterPathHelper.FixPosterPath(x.PosterPath); + if (shouldHide.UserId == x.RequestedUserId) + { + x.ShowSubscribe = false; + } + else + { + x.ShowSubscribe = true; + var hasSub = sub.FirstOrDefault(r => r.RequestId == x.Id); + x.Subscribed = hasSub != null; + } } } @@ -293,11 +293,8 @@ namespace Ombi.Core.Engine } var results = allRequests.Where(x => x.Title.Contains(search, CompareOptions.IgnoreCase)).ToList(); - results.ForEach(async x => - { - x.PosterPath = PosterPathHelper.FixPosterPath(x.PosterPath); - await CheckForSubscription(shouldHide, x); - }); + await CheckForSubscription(shouldHide, results); + return results; } @@ -493,7 +490,7 @@ namespace Ombi.Core.Engine RequestType = RequestType.Movie, }); - return new RequestEngineResult {Result = true, Message = $"{movieName} has been successfully added!", RequestId = model.Id}; + return new RequestEngineResult { Result = true, Message = $"{movieName} has been successfully added!", RequestId = model.Id }; } public async Task GetRemainingRequests(OmbiUser user) @@ -533,7 +530,7 @@ namespace Ombi.Core.Engine return new RequestQuotaCountModel() { - HasLimit = true, + HasLimit = true, Limit = limit, Remaining = count, NextRequest = DateTime.SpecifyKind(oldestRequestedAt.AddDays(7), DateTimeKind.Utc), diff --git a/src/Ombi.Core/Engine/TvRequestEngine.cs b/src/Ombi.Core/Engine/TvRequestEngine.cs index 796e2fe6a..28ab90a89 100644 --- a/src/Ombi.Core/Engine/TvRequestEngine.cs +++ b/src/Ombi.Core/Engine/TvRequestEngine.cs @@ -156,10 +156,10 @@ namespace Ombi.Core.Engine .ThenInclude(x => x.Episodes) .OrderByDescending(x => x.ChildRequests.Select(y => y.RequestedDate).FirstOrDefault()) .Skip(position).Take(count).ToListAsync(); - - } - allRequests.ForEach(async r => { await CheckForSubscription(shouldHide, r); }); + } + await CheckForSubscription(shouldHide, allRequests); + allRequests.ForEach(async r => { }); return new RequestsViewModel { @@ -194,7 +194,8 @@ namespace Ombi.Core.Engine { return new RequestsViewModel(); } - allRequests.ForEach(async r => { await CheckForSubscription(shouldHide, r); }); + + await CheckForSubscription(shouldHide, allRequests); return new RequestsViewModel { @@ -216,7 +217,7 @@ namespace Ombi.Core.Engine allRequests = await TvRepository.Get().ToListAsync(); } - allRequests.ForEach(async r => { await CheckForSubscription(shouldHide, r); }); + await CheckForSubscription(shouldHide, allRequests); return allRequests; } @@ -236,7 +237,7 @@ namespace Ombi.Core.Engine allRequests = await TvRepository.GetLite().ToListAsync(); } - allRequests.ForEach(async r => { await CheckForSubscription(shouldHide, r); }); + await CheckForSubscription(shouldHide, allRequests); return allRequests; } @@ -255,7 +256,7 @@ namespace Ombi.Core.Engine request = await TvRepository.Get().Where(x => x.Id == requestId).FirstOrDefaultAsync(); } - await CheckForSubscription(shouldHide, request); + await CheckForSubscription(shouldHide, new List{request}); return request; } @@ -304,7 +305,7 @@ namespace Ombi.Core.Engine allRequests = await TvRepository.GetChild().Include(x => x.SeasonRequests).Where(x => x.ParentRequestId == tvId).ToListAsync(); } - allRequests.ForEach(async r => { await CheckForSubscription(shouldHide, r); }); + await CheckForSubscription(shouldHide, allRequests); return allRequests; } @@ -323,7 +324,7 @@ namespace Ombi.Core.Engine } var results = await allRequests.Where(x => x.Title.Contains(search, CompareOptions.IgnoreCase)).ToListAsync(); - results.ForEach(async r => { await CheckForSubscription(shouldHide, r); }); + await CheckForSubscription(shouldHide, results); return results; } @@ -420,7 +421,7 @@ namespace Ombi.Core.Engine public async Task UpdateChildRequest(ChildRequests request) { - await TvRepository.UpdateChild(request); + await TvRepository.UpdateChild(request); return request; } @@ -438,14 +439,14 @@ namespace Ombi.Core.Engine // Delete the parent TvRepository.Db.TvRequests.Remove(parent); } - + await TvRepository.Db.SaveChangesAsync(); } public async Task RemoveTvRequest(int requestId) { var request = await TvRepository.Get().FirstOrDefaultAsync(x => x.Id == requestId); - await TvRepository.Delete(request); + await TvRepository.Delete(request); } public async Task UserHasRequest(string userId) @@ -520,26 +521,32 @@ namespace Ombi.Core.Engine } } - private async Task CheckForSubscription(HideResult shouldHide, TvRequests x) + private async Task CheckForSubscription(HideResult shouldHide, List x) { - foreach (var tv in x.ChildRequests) + foreach (var tvRequest in x) { - await CheckForSubscription(shouldHide, tv); + await CheckForSubscription(shouldHide, tvRequest.ChildRequests); } } - private async Task CheckForSubscription(HideResult shouldHide, ChildRequests x) + private async Task CheckForSubscription(HideResult shouldHide, List childRequests) { - if (shouldHide.UserId == x.RequestedUserId) + var sub = _subscriptionRepository.GetAll(); + var childIds = childRequests.Select(x => x.Id); + var relevantSubs = await sub.Where(s => + s.UserId == shouldHide.UserId && childIds.Contains(s.Id) && s.RequestType == RequestType.TvShow).ToListAsync(); + foreach (var x in childRequests) { - x.ShowSubscribe = false; - } - else - { - x.ShowSubscribe = true; - var sub = await _subscriptionRepository.GetAll().FirstOrDefaultAsync(s => - s.UserId == shouldHide.UserId && s.RequestId == x.Id && s.RequestType == RequestType.TvShow); - x.Subscribed = sub != null; + if (shouldHide.UserId == x.RequestedUserId) + { + x.ShowSubscribe = false; + } + else + { + x.ShowSubscribe = true; + var result = relevantSubs.FirstOrDefault(s => s.RequestId == x.Id); + x.Subscribed = result != null; + } } } @@ -560,7 +567,7 @@ namespace Ombi.Core.Engine return await AfterRequest(model.ChildRequests.FirstOrDefault()); } - private static List SortEpisodes(List items) + private static List SortEpisodes(List items) { foreach (var value in items) { @@ -597,7 +604,7 @@ namespace Ombi.Core.Engine var result = await TvSender.Send(model); if (result.Success) { - return new RequestEngineResult { Result = true, RequestId = model.Id}; + return new RequestEngineResult { Result = true, RequestId = model.Id }; } return new RequestEngineResult { @@ -650,10 +657,10 @@ namespace Ombi.Core.Engine DateTime oldestRequestedAt = await log.OrderBy(x => x.RequestDate) .Select(x => x.RequestDate) .FirstOrDefaultAsync(); - + return new RequestQuotaCountModel() { - HasLimit = true, + HasLimit = true, Limit = limit, Remaining = count, NextRequest = DateTime.SpecifyKind(oldestRequestedAt.AddDays(7), DateTimeKind.Utc), diff --git a/src/Ombi.Schedule/Jobs/Emby/EmbyAvaliabilityChecker.cs b/src/Ombi.Schedule/Jobs/Emby/EmbyAvaliabilityChecker.cs index 9c92bc509..d713cab80 100644 --- a/src/Ombi.Schedule/Jobs/Emby/EmbyAvaliabilityChecker.cs +++ b/src/Ombi.Schedule/Jobs/Emby/EmbyAvaliabilityChecker.cs @@ -213,7 +213,6 @@ namespace Ombi.Schedule.Jobs.Emby if (disposing) { - _movieRepo?.Dispose(); } _disposed = true; } diff --git a/src/Ombi.Schedule/Jobs/Emby/EmbyContentSync.cs b/src/Ombi.Schedule/Jobs/Emby/EmbyContentSync.cs index 362840203..2d4b168af 100644 --- a/src/Ombi.Schedule/Jobs/Emby/EmbyContentSync.cs +++ b/src/Ombi.Schedule/Jobs/Emby/EmbyContentSync.cs @@ -206,7 +206,6 @@ namespace Ombi.Schedule.Jobs.Emby if (disposing) { _settings?.Dispose(); - _repo?.Dispose(); } _disposed = true; } diff --git a/src/Ombi.Schedule/Jobs/Emby/EmbyEpisodeSync.cs b/src/Ombi.Schedule/Jobs/Emby/EmbyEpisodeSync.cs index 69ebdc42c..90236aef8 100644 --- a/src/Ombi.Schedule/Jobs/Emby/EmbyEpisodeSync.cs +++ b/src/Ombi.Schedule/Jobs/Emby/EmbyEpisodeSync.cs @@ -156,7 +156,6 @@ namespace Ombi.Schedule.Jobs.Emby if (disposing) { _settings?.Dispose(); - _repo?.Dispose(); } _disposed = true; } diff --git a/src/Ombi.Schedule/Jobs/Ombi/Interfaces/IssuesPurge.cs b/src/Ombi.Schedule/Jobs/Ombi/Interfaces/IssuesPurge.cs index 6a16aad70..e7b7f2633 100644 --- a/src/Ombi.Schedule/Jobs/Ombi/Interfaces/IssuesPurge.cs +++ b/src/Ombi.Schedule/Jobs/Ombi/Interfaces/IssuesPurge.cs @@ -49,7 +49,6 @@ namespace Ombi.Schedule.Jobs.Ombi if (disposing) { - _issuesRepository?.Dispose(); _settings?.Dispose(); } _disposed = true; diff --git a/src/Ombi.Schedule/Jobs/Ombi/MediaDatabaseRefresh.cs b/src/Ombi.Schedule/Jobs/Ombi/MediaDatabaseRefresh.cs index cf8cbd831..9c1c8b638 100644 --- a/src/Ombi.Schedule/Jobs/Ombi/MediaDatabaseRefresh.cs +++ b/src/Ombi.Schedule/Jobs/Ombi/MediaDatabaseRefresh.cs @@ -99,7 +99,6 @@ namespace Ombi.Schedule.Jobs.Ombi if (disposing) { - _plexRepo?.Dispose(); _settings?.Dispose(); } _disposed = true; diff --git a/src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs b/src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs index 503410d82..32254f09a 100644 --- a/src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs +++ b/src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs @@ -66,7 +66,7 @@ namespace Ombi.Schedule.Jobs.Ombi private readonly IPlexContentRepository _plex; private readonly IEmbyContentRepository _emby; - private readonly IExternalRepository _recentlyAddedLog; + private readonly IRepository _recentlyAddedLog; private readonly IMovieDbApi _movieApi; private readonly ITvMazeApi _tvApi; private readonly IEmailProvider _email; @@ -78,7 +78,7 @@ namespace Ombi.Schedule.Jobs.Ombi private readonly UserManager _userManager; private readonly ILogger _log; private readonly ILidarrApi _lidarrApi; - private readonly IRepository _lidarrAlbumRepository; + private readonly IExternalRepository _lidarrAlbumRepository; private readonly ISettingsService _lidarrSettings; private readonly ISettingsService _plexSettings; private readonly ISettingsService _embySettings; @@ -931,12 +931,9 @@ namespace Ombi.Schedule.Jobs.Ombi if (disposing) { - _plex?.Dispose(); - _emby?.Dispose(); _newsletterSettings?.Dispose(); _customizationSettings?.Dispose(); _emailSettings.Dispose(); - _recentlyAddedLog.Dispose(); _templateRepo?.Dispose(); _userManager?.Dispose(); } diff --git a/src/Ombi.Schedule/Jobs/Ombi/RefreshMetadata.cs b/src/Ombi.Schedule/Jobs/Ombi/RefreshMetadata.cs index 0ccb736dc..7766119cc 100644 --- a/src/Ombi.Schedule/Jobs/Ombi/RefreshMetadata.cs +++ b/src/Ombi.Schedule/Jobs/Ombi/RefreshMetadata.cs @@ -352,8 +352,6 @@ namespace Ombi.Schedule.Jobs.Ombi if (disposing) { - _plexRepo?.Dispose(); - _embyRepo?.Dispose(); _plexSettings?.Dispose(); } _disposed = true; diff --git a/src/Ombi.Schedule/Jobs/Plex/PlexAvailabilityChecker.cs b/src/Ombi.Schedule/Jobs/Plex/PlexAvailabilityChecker.cs index 72d7f5a2c..a2b1a56cf 100644 --- a/src/Ombi.Schedule/Jobs/Plex/PlexAvailabilityChecker.cs +++ b/src/Ombi.Schedule/Jobs/Plex/PlexAvailabilityChecker.cs @@ -193,8 +193,6 @@ namespace Ombi.Schedule.Jobs.Plex if (disposing) { - _movieRepo?.Dispose(); - _repo?.Dispose(); } _disposed = true; } diff --git a/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs b/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs index 70ab6878d..f290f2dc9 100644 --- a/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs +++ b/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs @@ -650,7 +650,6 @@ namespace Ombi.Schedule.Jobs.Plex if (disposing) { Plex?.Dispose(); - Repo?.Dispose(); EpisodeSync?.Dispose(); } _disposed = true; diff --git a/src/Ombi.Schedule/Jobs/Plex/PlexEpisodeSync.cs b/src/Ombi.Schedule/Jobs/Plex/PlexEpisodeSync.cs index 7414294be..dcf5ea395 100644 --- a/src/Ombi.Schedule/Jobs/Plex/PlexEpisodeSync.cs +++ b/src/Ombi.Schedule/Jobs/Plex/PlexEpisodeSync.cs @@ -206,7 +206,6 @@ namespace Ombi.Schedule.Jobs.Plex if (disposing) { - _repo?.Dispose(); _settings?.Dispose(); } _disposed = true; diff --git a/src/Ombi.Store/Context/MySql/OmbiMySqlContext.cs b/src/Ombi.Store/Context/MySql/OmbiMySqlContext.cs index a0d11f76a..073a0ed1a 100644 --- a/src/Ombi.Store/Context/MySql/OmbiMySqlContext.cs +++ b/src/Ombi.Store/Context/MySql/OmbiMySqlContext.cs @@ -12,5 +12,10 @@ namespace Ombi.Store.Context.MySql Database.Migrate(); } + + public override void Dispose() + { + base.Dispose(); + } } } \ No newline at end of file diff --git a/src/Ombi.Store/Repository/BaseRepository.cs b/src/Ombi.Store/Repository/BaseRepository.cs index 41a7eeb31..2df4d3467 100644 --- a/src/Ombi.Store/Repository/BaseRepository.cs +++ b/src/Ombi.Store/Repository/BaseRepository.cs @@ -107,25 +107,25 @@ namespace Ombi.Store.Repository } - private bool _disposed; - // Protected implementation of Dispose pattern. - protected virtual void Dispose(bool disposing) - { - if (_disposed) - return; + //private bool _disposed; + //// Protected implementation of Dispose pattern. + //protected virtual void Dispose(bool disposing) + //{ + // if (_disposed) + // return; - if (disposing) - { - _ctx?.Dispose(); - } + // if (disposing) + // { + // _ctx?.Dispose(); + // } - _disposed = true; - } + // _disposed = true; + //} - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } + //public void Dispose() + //{ + // Dispose(true); + // GC.SuppressFinalize(this); + //} } } \ No newline at end of file diff --git a/src/Ombi.Store/Repository/IExternalRepository.cs b/src/Ombi.Store/Repository/IExternalRepository.cs index de8b6db67..b22cb5ea8 100644 --- a/src/Ombi.Store/Repository/IExternalRepository.cs +++ b/src/Ombi.Store/Repository/IExternalRepository.cs @@ -9,7 +9,7 @@ using Ombi.Store.Entities; namespace Ombi.Store.Repository { - public interface IExternalRepository : IDisposable where T : Entity + public interface IExternalRepository where T : Entity { Task Find(object key); IQueryable GetAll(); diff --git a/src/Ombi.Store/Repository/IRepository.cs b/src/Ombi.Store/Repository/IRepository.cs index 810b586a3..fd7dcc86d 100644 --- a/src/Ombi.Store/Repository/IRepository.cs +++ b/src/Ombi.Store/Repository/IRepository.cs @@ -9,7 +9,7 @@ using Ombi.Store.Entities; namespace Ombi.Store.Repository { - public interface IRepository : IDisposable where T : Entity + public interface IRepository where T : Entity { Task Find(object key); IQueryable GetAll(); From 181bd5320249cdb305deb1b223cbc8b90bf1ffd7 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Sun, 10 Nov 2019 14:56:12 +0000 Subject: [PATCH 03/11] Fixed the notifications issue --- src/Ombi.Core/Engine/MovieRequestEngine.cs | 10 +- src/Ombi.Core/Engine/MusicRequestEngine.cs | 8 +- src/Ombi.Core/Engine/TvRequestEngine.cs | 11 +- src/Ombi.Core/Helpers/NotificationHelper.cs | 108 ++++++++++------- src/Ombi.Core/Senders/INotificationHelper.cs | 17 +-- src/Ombi.Core/Senders/MovieSender.cs | 2 +- src/Ombi.Core/Senders/MusicSender.cs | 2 +- src/Ombi.Core/Senders/TvSender.cs | 2 +- src/Ombi.DependencyInjection/IocExtensions.cs | 3 +- .../JobDataKeys.cs | 3 +- src/Ombi.Helpers/Ombi.Helpers.csproj | 1 + .../OmbiQuartz.cs | 10 +- .../Interfaces/INotificationService.cs | 7 +- src/Ombi.Notifications/NotificationService.cs | 109 +++++++----------- src/Ombi.Schedule/IocJobFactory.cs | 16 +-- .../Jobs/Emby/EmbyAvaliabilityChecker.cs | 13 ++- .../Jobs/Emby/EmbyEpisodeSync.cs | 1 + .../Jobs/Lidarr/LidarrAvailabilityChecker.cs | 10 +- .../Jobs/Plex/PlexAvailabilityChecker.cs | 10 +- src/Ombi.Schedule/OmbiScheduler.cs | 7 ++ src/Ombi.Schedule/QuartzJobRunner.cs | 27 +++++ src/Ombi/Controllers/IssuesController.cs | 10 +- 22 files changed, 210 insertions(+), 177 deletions(-) rename src/{Ombi.Schedule => Ombi.Helpers}/JobDataKeys.cs (52%) rename src/{Ombi.Schedule => Ombi.Helpers}/OmbiQuartz.cs (90%) create mode 100644 src/Ombi.Schedule/QuartzJobRunner.cs diff --git a/src/Ombi.Core/Engine/MovieRequestEngine.cs b/src/Ombi.Core/Engine/MovieRequestEngine.cs index 51a1c14db..751cc9ebf 100644 --- a/src/Ombi.Core/Engine/MovieRequestEngine.cs +++ b/src/Ombi.Core/Engine/MovieRequestEngine.cs @@ -318,7 +318,7 @@ namespace Ombi.Core.Engine request.Denied = true; request.DeniedReason = denyReason; // We are denying a request - NotificationHelper.Notify(request, NotificationType.RequestDeclined); + await NotificationHelper.Notify(request, NotificationType.RequestDeclined); await MovieRepository.Update(request); return new RequestEngineResult @@ -346,7 +346,7 @@ namespace Ombi.Core.Engine var canNotify = await RunSpecificRule(request, SpecificRules.CanSendNotification); if (canNotify.Success) { - NotificationHelper.Notify(request, NotificationType.RequestApproved); + await NotificationHelper.Notify(request, NotificationType.RequestApproved); } if (request.Approved) @@ -462,7 +462,7 @@ namespace Ombi.Core.Engine request.Available = true; request.MarkedAsAvailable = DateTime.Now; - NotificationHelper.Notify(request, NotificationType.RequestAvailable); + await NotificationHelper.Notify(request, NotificationType.RequestAvailable); await MovieRepository.Update(request); return new RequestEngineResult @@ -478,8 +478,8 @@ namespace Ombi.Core.Engine var result = await RunSpecificRule(model, SpecificRules.CanSendNotification); if (result.Success) - { - NotificationHelper.NewRequest(model); + { + await NotificationHelper.NewRequest(model); } await _requestLog.Add(new RequestLog diff --git a/src/Ombi.Core/Engine/MusicRequestEngine.cs b/src/Ombi.Core/Engine/MusicRequestEngine.cs index 8457de515..ce69cb0b3 100644 --- a/src/Ombi.Core/Engine/MusicRequestEngine.cs +++ b/src/Ombi.Core/Engine/MusicRequestEngine.cs @@ -314,7 +314,7 @@ namespace Ombi.Core.Engine request.Denied = true; request.DeniedReason = reason; // We are denying a request - NotificationHelper.Notify(request, NotificationType.RequestDeclined); + await NotificationHelper.Notify(request, NotificationType.RequestDeclined); await MusicRepository.Update(request); return new RequestEngineResult @@ -342,7 +342,7 @@ namespace Ombi.Core.Engine var canNotify = await RunSpecificRule(request, SpecificRules.CanSendNotification); if (canNotify.Success) { - NotificationHelper.Notify(request, NotificationType.RequestApproved); + await NotificationHelper.Notify(request, NotificationType.RequestApproved); } if (request.Approved) @@ -469,7 +469,7 @@ namespace Ombi.Core.Engine request.Available = true; request.MarkedAsAvailable = DateTime.Now; - NotificationHelper.Notify(request, NotificationType.RequestAvailable); + await NotificationHelper.Notify(request, NotificationType.RequestAvailable); await MusicRepository.Update(request); return new RequestEngineResult @@ -486,7 +486,7 @@ namespace Ombi.Core.Engine var result = await RunSpecificRule(model, SpecificRules.CanSendNotification); if (result.Success) { - NotificationHelper.NewRequest(model); + await NotificationHelper.NewRequest(model); } await _requestLog.Add(new RequestLog diff --git a/src/Ombi.Core/Engine/TvRequestEngine.cs b/src/Ombi.Core/Engine/TvRequestEngine.cs index 28ab90a89..74ba55d31 100644 --- a/src/Ombi.Core/Engine/TvRequestEngine.cs +++ b/src/Ombi.Core/Engine/TvRequestEngine.cs @@ -159,7 +159,6 @@ namespace Ombi.Core.Engine } await CheckForSubscription(shouldHide, allRequests); - allRequests.ForEach(async r => { }); return new RequestsViewModel { @@ -389,7 +388,7 @@ namespace Ombi.Core.Engine if (request.Approved) { - NotificationHelper.Notify(request, NotificationType.RequestApproved); + await NotificationHelper.Notify(request, NotificationType.RequestApproved); // Autosend await TvSender.Send(request); } @@ -412,7 +411,7 @@ namespace Ombi.Core.Engine request.Denied = true; request.DeniedReason = reason; await TvRepository.UpdateChild(request); - NotificationHelper.Notify(request, NotificationType.RequestDeclined); + await NotificationHelper.Notify(request, NotificationType.RequestDeclined); return new RequestEngineResult { Result = true @@ -500,7 +499,7 @@ namespace Ombi.Core.Engine } } await TvRepository.UpdateChild(request); - NotificationHelper.Notify(request, NotificationType.RequestAvailable); + await NotificationHelper.Notify(request, NotificationType.RequestAvailable); return new RequestEngineResult { Result = true, @@ -585,7 +584,7 @@ namespace Ombi.Core.Engine var sendRuleResult = await RunSpecificRule(model, SpecificRules.CanSendNotification); if (sendRuleResult.Success) { - NotificationHelper.NewRequest(model); + await NotificationHelper.NewRequest(model); } await _requestLog.Add(new RequestLog @@ -600,7 +599,7 @@ namespace Ombi.Core.Engine if (model.Approved) { // Autosend - NotificationHelper.Notify(model, NotificationType.RequestApproved); + await NotificationHelper.Notify(model, NotificationType.RequestApproved); var result = await TvSender.Send(model); if (result.Success) { diff --git a/src/Ombi.Core/Helpers/NotificationHelper.cs b/src/Ombi.Core/Helpers/NotificationHelper.cs index 1615b24f7..f94e8f0db 100644 --- a/src/Ombi.Core/Helpers/NotificationHelper.cs +++ b/src/Ombi.Core/Helpers/NotificationHelper.cs @@ -1,5 +1,6 @@ using System; -using Hangfire; +using System.Collections.Generic; +using System.Threading.Tasks; using Ombi.Core.Notifications; using Ombi.Helpers; using Ombi.Notifications.Models; @@ -9,13 +10,7 @@ namespace Ombi.Core { public class NotificationHelper : INotificationHelper { - public NotificationHelper(INotificationService service) - { - NotificationService = service; - } - private INotificationService NotificationService { get; } - - public void NewRequest(FullBaseRequest model) + public async Task NewRequest(FullBaseRequest model) { var notificationModel = new NotificationOptions { @@ -24,11 +19,13 @@ namespace Ombi.Core NotificationType = NotificationType.NewRequest, RequestType = model.RequestType }; - BackgroundJob.Enqueue(() => NotificationService.Publish(notificationModel)); - + await OmbiQuartz.TriggerJob(nameof(INotificationService), "Notifications", new Dictionary + { + {JobDataKeys.NotificationOptions, notificationModel} + }); } - public void NewRequest(ChildRequests model) + public async Task NewRequest(ChildRequests model) { var notificationModel = new NotificationOptions { @@ -36,11 +33,14 @@ namespace Ombi.Core DateTime = DateTime.Now, NotificationType = NotificationType.NewRequest, RequestType = model.RequestType - }; - BackgroundJob.Enqueue(() => NotificationService.Publish(notificationModel)); + }; + await OmbiQuartz.TriggerJob(nameof(INotificationService), "Notifications", new Dictionary + { + {JobDataKeys.NotificationOptions, notificationModel} + }); } - public void NewRequest(AlbumRequest model) + public async Task NewRequest(AlbumRequest model) { var notificationModel = new NotificationOptions { @@ -48,38 +48,15 @@ namespace Ombi.Core DateTime = DateTime.Now, NotificationType = NotificationType.NewRequest, RequestType = model.RequestType - }; - BackgroundJob.Enqueue(() => NotificationService.Publish(notificationModel)); - } - - - public void Notify(MovieRequests model, NotificationType type) - { - var notificationModel = new NotificationOptions + }; + await OmbiQuartz.TriggerJob(nameof(INotificationService), "Notifications", new Dictionary { - RequestId = model.Id, - DateTime = DateTime.Now, - NotificationType = type, - RequestType = model.RequestType, - Recipient = model.RequestedUser?.Email ?? string.Empty - }; - - BackgroundJob.Enqueue(() => NotificationService.Publish(notificationModel)); - } - public void Notify(ChildRequests model, NotificationType type) - { - var notificationModel = new NotificationOptions - { - RequestId = model.Id, - DateTime = DateTime.Now, - NotificationType = type, - RequestType = model.RequestType, - Recipient = model.RequestedUser?.Email ?? string.Empty - }; - BackgroundJob.Enqueue(() => NotificationService.Publish(notificationModel)); + {JobDataKeys.NotificationOptions, notificationModel} + }); } - public void Notify(AlbumRequest model, NotificationType type) + + public async Task Notify(MovieRequests model, NotificationType type) { var notificationModel = new NotificationOptions { @@ -90,7 +67,50 @@ namespace Ombi.Core Recipient = model.RequestedUser?.Email ?? string.Empty }; - BackgroundJob.Enqueue(() => NotificationService.Publish(notificationModel)); + await OmbiQuartz.TriggerJob(nameof(INotificationService), "Notifications", new Dictionary + { + {JobDataKeys.NotificationOptions, notificationModel} + }); + } + public async Task Notify(ChildRequests model, NotificationType type) + { + var notificationModel = new NotificationOptions + { + RequestId = model.Id, + DateTime = DateTime.Now, + NotificationType = type, + RequestType = model.RequestType, + Recipient = model.RequestedUser?.Email ?? string.Empty + }; + await OmbiQuartz.TriggerJob(nameof(INotificationService), "Notifications", new Dictionary + { + {JobDataKeys.NotificationOptions, notificationModel} + }); + } + + public async Task Notify(AlbumRequest model, NotificationType type) + { + var notificationModel = new NotificationOptions + { + RequestId = model.Id, + DateTime = DateTime.Now, + NotificationType = type, + RequestType = model.RequestType, + Recipient = model.RequestedUser?.Email ?? string.Empty + }; + + await OmbiQuartz.TriggerJob(nameof(INotificationService), "Notifications", new Dictionary + { + {JobDataKeys.NotificationOptions, notificationModel} + }); + } + + public async Task Notify(NotificationOptions model) + { + await OmbiQuartz.TriggerJob(nameof(INotificationService), "Notifications", new Dictionary + { + {JobDataKeys.NotificationOptions, model} + }); } } } \ No newline at end of file diff --git a/src/Ombi.Core/Senders/INotificationHelper.cs b/src/Ombi.Core/Senders/INotificationHelper.cs index 4ba47d761..70947a57e 100644 --- a/src/Ombi.Core/Senders/INotificationHelper.cs +++ b/src/Ombi.Core/Senders/INotificationHelper.cs @@ -1,16 +1,19 @@ -using Ombi.Core.Models.Requests; +using System.Threading.Tasks; +using Ombi.Core.Models.Requests; using Ombi.Helpers; +using Ombi.Notifications.Models; using Ombi.Store.Entities.Requests; namespace Ombi.Core { public interface INotificationHelper { - void NewRequest(FullBaseRequest model); - void NewRequest(ChildRequests model); - void NewRequest(AlbumRequest model); - void Notify(MovieRequests model, NotificationType type); - void Notify(ChildRequests model, NotificationType type); - void Notify(AlbumRequest model, NotificationType type); + Task NewRequest(FullBaseRequest model); + Task NewRequest(ChildRequests model); + Task NewRequest(AlbumRequest model); + Task Notify(MovieRequests model, NotificationType type); + Task Notify(ChildRequests model, NotificationType type); + Task Notify(AlbumRequest model, NotificationType type); + Task Notify(NotificationOptions model); } } \ No newline at end of file diff --git a/src/Ombi.Core/Senders/MovieSender.cs b/src/Ombi.Core/Senders/MovieSender.cs index 567df43b5..c9aa5e4f2 100644 --- a/src/Ombi.Core/Senders/MovieSender.cs +++ b/src/Ombi.Core/Senders/MovieSender.cs @@ -95,7 +95,7 @@ namespace Ombi.Core.Senders Type = RequestType.Movie, RetryCount = 0 }); - _notificationHelper.Notify(model, NotificationType.ItemAddedToFaultQueue); + await _notificationHelper.Notify(model, NotificationType.ItemAddedToFaultQueue); } } diff --git a/src/Ombi.Core/Senders/MusicSender.cs b/src/Ombi.Core/Senders/MusicSender.cs index 04544c6be..e4bf27855 100644 --- a/src/Ombi.Core/Senders/MusicSender.cs +++ b/src/Ombi.Core/Senders/MusicSender.cs @@ -65,7 +65,7 @@ namespace Ombi.Core.Senders Type = RequestType.Album, RetryCount = 0 }); - _notificationHelper.Notify(model, NotificationType.ItemAddedToFaultQueue); + await _notificationHelper.Notify(model, NotificationType.ItemAddedToFaultQueue); } } diff --git a/src/Ombi.Core/Senders/TvSender.cs b/src/Ombi.Core/Senders/TvSender.cs index 3a3e34745..5cf28fa8a 100644 --- a/src/Ombi.Core/Senders/TvSender.cs +++ b/src/Ombi.Core/Senders/TvSender.cs @@ -128,7 +128,7 @@ namespace Ombi.Core.Senders Type = RequestType.TvShow, RetryCount = 0 }); - _notificationHelper.Notify(model, NotificationType.ItemAddedToFaultQueue); + await _notificationHelper.Notify(model, NotificationType.ItemAddedToFaultQueue); } } diff --git a/src/Ombi.DependencyInjection/IocExtensions.cs b/src/Ombi.DependencyInjection/IocExtensions.cs index df0162c1a..c4e66c6f5 100644 --- a/src/Ombi.DependencyInjection/IocExtensions.cs +++ b/src/Ombi.DependencyInjection/IocExtensions.cs @@ -181,7 +181,8 @@ namespace Ombi.DependencyInjection public static void RegisterJobs(this IServiceCollection services) { - services.AddSingleton(provider => new IoCJobFactory(provider)); + services.AddSingleton(); + services.AddSingleton(); services.AddTransient(); services.AddTransient(); diff --git a/src/Ombi.Schedule/JobDataKeys.cs b/src/Ombi.Helpers/JobDataKeys.cs similarity index 52% rename from src/Ombi.Schedule/JobDataKeys.cs rename to src/Ombi.Helpers/JobDataKeys.cs index 46d2dee2a..e0e2f7451 100644 --- a/src/Ombi.Schedule/JobDataKeys.cs +++ b/src/Ombi.Helpers/JobDataKeys.cs @@ -1,7 +1,8 @@ -namespace Ombi.Schedule +namespace Ombi.Helpers { public class JobDataKeys { public const string RecentlyAddedSearch = "recentlyAddedSearch"; + public const string NotificationOptions = nameof(NotificationOptions); } } \ No newline at end of file diff --git a/src/Ombi.Helpers/Ombi.Helpers.csproj b/src/Ombi.Helpers/Ombi.Helpers.csproj index 5dedaff61..8af8b9861 100644 --- a/src/Ombi.Helpers/Ombi.Helpers.csproj +++ b/src/Ombi.Helpers/Ombi.Helpers.csproj @@ -14,6 +14,7 @@ + diff --git a/src/Ombi.Schedule/OmbiQuartz.cs b/src/Ombi.Helpers/OmbiQuartz.cs similarity index 90% rename from src/Ombi.Schedule/OmbiQuartz.cs rename to src/Ombi.Helpers/OmbiQuartz.cs index 715bb187b..7979bc2a7 100644 --- a/src/Ombi.Schedule/OmbiQuartz.cs +++ b/src/Ombi.Helpers/OmbiQuartz.cs @@ -1,11 +1,10 @@ using System.Collections.Generic; using System.Threading.Tasks; -using Ombi.Helpers; using Quartz; using Quartz.Impl; using Quartz.Spi; -namespace Ombi.Schedule +namespace Ombi.Helpers { public class OmbiQuartz { @@ -78,7 +77,12 @@ namespace Ombi.Schedule { await Scheduler.TriggerJob(new JobKey(jobName, group)); } - + + public static async Task TriggerJob(string jobName, string group, IDictionary data) + { + await Scheduler.TriggerJob(new JobKey(jobName, group), new JobDataMap(data)); + } + public static async Task Start() { await Scheduler.Start(); diff --git a/src/Ombi.Notifications/Interfaces/INotificationService.cs b/src/Ombi.Notifications/Interfaces/INotificationService.cs index f8731b4af..f6a3761c3 100644 --- a/src/Ombi.Notifications/Interfaces/INotificationService.cs +++ b/src/Ombi.Notifications/Interfaces/INotificationService.cs @@ -1,13 +1,12 @@ using System.Threading.Tasks; using Ombi.Notifications; using Ombi.Notifications.Models; +using Quartz; namespace Ombi.Core.Notifications { - public interface INotificationService + public interface INotificationService : IJob { - Task Publish(NotificationOptions model); - Task Publish(NotificationOptions model, Ombi.Settings.Settings.Models.Settings settings); - Task PublishTest(NotificationOptions model, Ombi.Settings.Settings.Models.Settings settings, INotification type); + } } \ No newline at end of file diff --git a/src/Ombi.Notifications/NotificationService.cs b/src/Ombi.Notifications/NotificationService.cs index c2985a21b..8a24382aa 100644 --- a/src/Ombi.Notifications/NotificationService.cs +++ b/src/Ombi.Notifications/NotificationService.cs @@ -7,16 +7,56 @@ using Microsoft.Extensions.Logging; using Ombi.Core.Notifications; using Ombi.Helpers; using Ombi.Notifications.Models; +using Quartz; namespace Ombi.Notifications { public class NotificationService : INotificationService { + private readonly IServiceProvider _provider; + public NotificationService(IServiceProvider provider, ILogger log) { + _provider = provider; Log = log; NotificationAgents = new List(); + PopulateAgents(); + } + + private List NotificationAgents { get; } + private ILogger Log { get; } + + /// + /// Sends a notification to the user. This one is used in normal notification scenarios + /// + /// The model. + /// + public async Task Execute(IJobExecutionContext context) + { + JobDataMap dataMap = context.MergedJobDataMap; + var model = (NotificationOptions)dataMap.Get(JobDataKeys.NotificationOptions); + foreach (var agent in NotificationAgents) + { + await NotifyAsync(agent, model); + } + } + + private async Task NotifyAsync(INotification notification, NotificationOptions model) + { + try + { + await notification.NotifyAsync(model); + } + catch (Exception ex) + { + Log.LogError(LoggingEvents.Notification, ex, "Failed to notify for notification: {@notification}", notification); + } + + } + + private void PopulateAgents() + { var baseSearchType = typeof(BaseNotification<>).Name; var ass = typeof(NotificationService).GetTypeInfo().Assembly; @@ -32,7 +72,7 @@ namespace Ombi.Notifications var services = new List(); foreach (var param in ctor.GetParameters()) { - services.Add(provider.GetService(param.ParameterType)); + services.Add(_provider.GetService(param.ParameterType)); } var item = Activator.CreateInstance(type, services.ToArray()); @@ -40,72 +80,5 @@ namespace Ombi.Notifications } } } - - private List NotificationAgents { get; } - private ILogger Log { get; } - - /// ^ - /// Sends a notification to the user. This one is used in normal notification scenarios - /// - /// The model. - /// - public async Task Publish(NotificationOptions model) - { - var notificationTasks = new List(); - - foreach (var agent in NotificationAgents) - { - notificationTasks.Add(NotifyAsync(agent,model)); - } - await Task.WhenAll(notificationTasks).ConfigureAwait(false); - } - - /// - /// Sends a notification to the user, this is usually for testing the settings. - /// - /// The model. - /// The settings. - /// - public async Task Publish(NotificationOptions model, Settings.Settings.Models.Settings settings) - { - var notificationTasks = NotificationAgents.Select(notification => NotifyAsync(notification, model, settings)); - - await Task.WhenAll(notificationTasks).ConfigureAwait(false); - } - - - private async Task NotifyAsync(INotification notification, NotificationOptions model) - { - try - { - await notification.NotifyAsync(model).ConfigureAwait(false); - } - catch (Exception ex) - { - Log.LogError(LoggingEvents.Notification, ex, "Failed to notify for notification: {@notification}", notification); - } - - } - - private async Task NotifyAsync(INotification notification, NotificationOptions model, Ombi.Settings.Settings.Models.Settings settings) - { - if (model.RequestId == 0) - { - throw new ArgumentException("RequestId is not set"); - } - try - { - await notification.NotifyAsync(model, settings).ConfigureAwait(false); - } - catch (Exception ex) - { - throw new InvalidOperationException(ex.Message); - } - } - - public async Task PublishTest(NotificationOptions model, Ombi.Settings.Settings.Models.Settings settings, INotification type) - { - await type.NotifyAsync(model, settings); - } } } \ No newline at end of file diff --git a/src/Ombi.Schedule/IocJobFactory.cs b/src/Ombi.Schedule/IocJobFactory.cs index 795c1fec5..abb458e39 100644 --- a/src/Ombi.Schedule/IocJobFactory.cs +++ b/src/Ombi.Schedule/IocJobFactory.cs @@ -7,26 +7,18 @@ namespace Ombi.Schedule { public class IoCJobFactory : IJobFactory { - private readonly IServiceProvider _factory; - - public IoCJobFactory(IServiceProvider factory) + private readonly IServiceProvider _serviceProvider; + public IoCJobFactory(IServiceProvider serviceProvider) { - _factory = factory; + _serviceProvider = serviceProvider; } public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler) { - var scopeFactory = _factory.GetService(); - var scope = scopeFactory.CreateScope(); - var scopedContainer = scope.ServiceProvider; - - var implementation = scopedContainer.GetRequiredService(bundle.JobDetail.JobType) as IJob; - return implementation; + return _serviceProvider.GetRequiredService(); } public void ReturnJob(IJob job) { - var disposable = job as IDisposable; - disposable?.Dispose(); } } } \ No newline at end of file diff --git a/src/Ombi.Schedule/Jobs/Emby/EmbyAvaliabilityChecker.cs b/src/Ombi.Schedule/Jobs/Emby/EmbyAvaliabilityChecker.cs index d713cab80..ade23329d 100644 --- a/src/Ombi.Schedule/Jobs/Emby/EmbyAvaliabilityChecker.cs +++ b/src/Ombi.Schedule/Jobs/Emby/EmbyAvaliabilityChecker.cs @@ -31,6 +31,7 @@ using System.Threading.Tasks; using Hangfire; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; +using Ombi.Core; using Ombi.Core.Notifications; using Ombi.Helpers; using Ombi.Notifications.Models; @@ -45,7 +46,7 @@ namespace Ombi.Schedule.Jobs.Emby public class EmbyAvaliabilityChecker : IEmbyAvaliabilityChecker { public EmbyAvaliabilityChecker(IEmbyContentRepository repo, ITvRequestRepository t, IMovieRequestRepository m, - INotificationService n, ILogger log) + INotificationHelper n, ILogger log) { _repo = repo; _tvRepo = t; @@ -57,7 +58,7 @@ namespace Ombi.Schedule.Jobs.Emby private readonly ITvRequestRepository _tvRepo; private readonly IMovieRequestRepository _movieRepo; private readonly IEmbyContentRepository _repo; - private readonly INotificationService _notificationService; + private readonly INotificationHelper _notificationService; private readonly ILogger _log; public async Task Execute(IJobExecutionContext job) @@ -100,14 +101,14 @@ namespace Ombi.Schedule.Jobs.Emby _log.LogDebug("MovieId: {0}, RequestUser: {1}", movie.Id, recipient); - BackgroundJob.Enqueue(() => _notificationService.Publish(new NotificationOptions + await _notificationService.Notify(new NotificationOptions { DateTime = DateTime.Now, NotificationType = NotificationType.RequestAvailable, RequestId = movie.Id, RequestType = RequestType.Movie, Recipient = recipient, - })); + }); } } await _movieRepo.Save(); @@ -191,14 +192,14 @@ namespace Ombi.Schedule.Jobs.Emby // We have fulfulled this request! child.Available = true; child.MarkedAsAvailable = DateTime.Now; - BackgroundJob.Enqueue(() => _notificationService.Publish(new NotificationOptions + await _notificationService.Notify(new NotificationOptions { DateTime = DateTime.Now, NotificationType = NotificationType.RequestAvailable, RequestId = child.Id, RequestType = RequestType.TvShow, Recipient = child.RequestedUser.Email - })); + }); } } diff --git a/src/Ombi.Schedule/Jobs/Emby/EmbyEpisodeSync.cs b/src/Ombi.Schedule/Jobs/Emby/EmbyEpisodeSync.cs index 90236aef8..140d53b0a 100644 --- a/src/Ombi.Schedule/Jobs/Emby/EmbyEpisodeSync.cs +++ b/src/Ombi.Schedule/Jobs/Emby/EmbyEpisodeSync.cs @@ -34,6 +34,7 @@ using Microsoft.Extensions.Logging; using Ombi.Api.Emby; using Ombi.Core.Settings; using Ombi.Core.Settings.Models.External; +using Ombi.Helpers; using Ombi.Store.Entities; using Ombi.Store.Repository; using Quartz; diff --git a/src/Ombi.Schedule/Jobs/Lidarr/LidarrAvailabilityChecker.cs b/src/Ombi.Schedule/Jobs/Lidarr/LidarrAvailabilityChecker.cs index 340164bd5..bdc697773 100644 --- a/src/Ombi.Schedule/Jobs/Lidarr/LidarrAvailabilityChecker.cs +++ b/src/Ombi.Schedule/Jobs/Lidarr/LidarrAvailabilityChecker.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using Hangfire; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; +using Ombi.Core; using Ombi.Core.Notifications; using Ombi.Helpers; using Ombi.Notifications.Models; @@ -18,7 +19,7 @@ namespace Ombi.Schedule.Jobs.Lidarr public class LidarrAvailabilityChecker : ILidarrAvailabilityChecker { public LidarrAvailabilityChecker(IMusicRequestRepository requests, IRepository albums, ILogger log, - IBackgroundJobClient job, INotificationService notification) + IBackgroundJobClient job, INotificationHelper notification) { _cachedAlbums = albums; _requestRepository = requests; @@ -31,7 +32,7 @@ namespace Ombi.Schedule.Jobs.Lidarr private readonly IRepository _cachedAlbums; private readonly ILogger _logger; private readonly IBackgroundJobClient _job; - private readonly INotificationService _notificationService; + private readonly INotificationHelper _notificationService; public async Task Start() { @@ -59,14 +60,15 @@ namespace Ombi.Schedule.Jobs.Lidarr _logger.LogDebug("AlbumId: {0}, RequestUser: {1}", albumRequest.Id, recipient); - _job.Enqueue(() => _notificationService.Publish(new NotificationOptions + + await _notificationService.Notify(new NotificationOptions { DateTime = DateTime.Now, NotificationType = NotificationType.RequestAvailable, RequestId = albumRequest.Id, RequestType = RequestType.Album, Recipient = recipient, - })); + }); } } } diff --git a/src/Ombi.Schedule/Jobs/Plex/PlexAvailabilityChecker.cs b/src/Ombi.Schedule/Jobs/Plex/PlexAvailabilityChecker.cs index a2b1a56cf..78fce3949 100644 --- a/src/Ombi.Schedule/Jobs/Plex/PlexAvailabilityChecker.cs +++ b/src/Ombi.Schedule/Jobs/Plex/PlexAvailabilityChecker.cs @@ -5,6 +5,7 @@ using System.Threading.Tasks; using Hangfire; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; +using Ombi.Core; using Ombi.Core.Notifications; using Ombi.Helpers; using Ombi.Notifications.Models; @@ -19,7 +20,7 @@ namespace Ombi.Schedule.Jobs.Plex public class PlexAvailabilityChecker : IPlexAvailabilityChecker { public PlexAvailabilityChecker(IPlexContentRepository repo, ITvRequestRepository tvRequest, IMovieRequestRepository movies, - INotificationService notification, IBackgroundJobClient background, ILogger log) + INotificationHelper notification, IBackgroundJobClient background, ILogger log) { _tvRepo = tvRequest; _repo = repo; @@ -32,7 +33,7 @@ namespace Ombi.Schedule.Jobs.Plex private readonly ITvRequestRepository _tvRepo; private readonly IMovieRequestRepository _movieRepo; private readonly IPlexContentRepository _repo; - private readonly INotificationService _notificationService; + private readonly INotificationHelper _notificationService; private readonly IBackgroundJobClient _backgroundJobClient; private readonly ILogger _log; @@ -126,7 +127,8 @@ namespace Ombi.Schedule.Jobs.Plex // We have ful-fulled this request! child.Available = true; child.MarkedAsAvailable = DateTime.Now; - await _notificationService.Publish(new NotificationOptions + + await _notificationService.Notify(new NotificationOptions { DateTime = DateTime.Now, NotificationType = NotificationType.RequestAvailable, @@ -170,7 +172,7 @@ namespace Ombi.Schedule.Jobs.Plex item.RequestId = movie.Id; _log.LogInformation("[PAC] - Movie request {0} is now available, sending notification", $"{movie.Title} - {movie.Id}"); - await _notificationService.Publish(new NotificationOptions + await _notificationService.Notify(new NotificationOptions { DateTime = DateTime.Now, NotificationType = NotificationType.RequestAvailable, diff --git a/src/Ombi.Schedule/OmbiScheduler.cs b/src/Ombi.Schedule/OmbiScheduler.cs index cfe3bbf27..ac095b354 100644 --- a/src/Ombi.Schedule/OmbiScheduler.cs +++ b/src/Ombi.Schedule/OmbiScheduler.cs @@ -2,7 +2,9 @@ using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; +using Ombi.Core.Notifications; using Ombi.Core.Settings; +using Ombi.Helpers; using Ombi.Schedule.Jobs; using Ombi.Schedule.Jobs.Couchpotato; using Ombi.Schedule.Jobs.Emby; @@ -53,6 +55,7 @@ namespace Ombi.Schedule await AddEmby(s); await AddDvrApps(s); await AddSystem(s); + await AddNotifications(s); // Run Quartz await OmbiQuartz.Start(); @@ -93,5 +96,9 @@ namespace Ombi.Schedule await OmbiQuartz.Instance.AddJob(nameof(IEmbyAvaliabilityChecker), "Emby", null); await OmbiQuartz.Instance.AddJob(nameof(IEmbyUserImporter), "Emby", JobSettingsHelper.UserImporter(s)); } + private static async Task AddNotifications(JobSettings s) + { + await OmbiQuartz.Instance.AddJob(nameof(INotificationService), "Notifications", null); + } } } \ No newline at end of file diff --git a/src/Ombi.Schedule/QuartzJobRunner.cs b/src/Ombi.Schedule/QuartzJobRunner.cs new file mode 100644 index 000000000..2a8a39db0 --- /dev/null +++ b/src/Ombi.Schedule/QuartzJobRunner.cs @@ -0,0 +1,27 @@ +using System; +using System.Threading.Tasks; +using Microsoft.Extensions.DependencyInjection; +using Quartz; + +namespace Ombi.Schedule +{ + public class QuartzJobRunner : IJob + { + private readonly IServiceProvider _serviceProvider; + public QuartzJobRunner(IServiceProvider serviceProvider) + { + _serviceProvider = serviceProvider; + } + + public async Task Execute(IJobExecutionContext context) + { + using (var scope = _serviceProvider.CreateScope()) + { + var jobType = context.JobDetail.JobType; + var job = scope.ServiceProvider.GetRequiredService(jobType) as IJob; + + await job.Execute(context); + } + } + } +} \ No newline at end of file diff --git a/src/Ombi/Controllers/IssuesController.cs b/src/Ombi/Controllers/IssuesController.cs index 3c8e9c719..72d82fc25 100644 --- a/src/Ombi/Controllers/IssuesController.cs +++ b/src/Ombi/Controllers/IssuesController.cs @@ -27,7 +27,7 @@ namespace Ombi.Controllers public class IssuesController : ControllerBase { public IssuesController(IRepository categories, IRepository issues, IRepository comments, - UserManager userManager, INotificationService notify) + UserManager userManager, INotificationHelper notify) { _categories = categories; _issues = issues; @@ -40,7 +40,7 @@ namespace Ombi.Controllers private readonly IRepository _issues; private readonly IRepository _issueComments; private readonly UserManager _userManager; - private readonly INotificationService _notification; + private readonly INotificationHelper _notification; /// /// Get's all categories @@ -152,7 +152,7 @@ namespace Ombi.Controllers AddIssueNotificationSubstitutes(notificationModel, i, User.Identity.Name); - BackgroundJob.Enqueue(() => _notification.Publish(notificationModel)); + await _notification.Notify(notificationModel); return i.Id; } @@ -239,7 +239,7 @@ namespace Ombi.Controllers notificationModel.Recipient = user.Email; } - BackgroundJob.Enqueue(() => _notification.Publish(notificationModel)); + await _notification.Notify(notificationModel); return await _issueComments.Add(newComment); } @@ -292,7 +292,7 @@ namespace Ombi.Controllers }; AddIssueNotificationSubstitutes(notificationModel, issue, issue.UserReported?.UserAlias ?? string.Empty); - BackgroundJob.Enqueue(() => _notification.Publish(notificationModel)); + await _notification.Notify(notificationModel); } From b41fcb467e76a03f3d8c76de65f9234e7b601f30 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Sun, 10 Nov 2019 15:05:01 +0000 Subject: [PATCH 04/11] Removed hangfire completly from Ombi --- src/Ombi.Core/Ombi.Core.csproj | 1 - src/Ombi.DependencyInjection/IocExtensions.cs | 2 -- src/Ombi.Schedule.Tests/OmbiQuartzTests.cs | 1 + .../PlexAvailabilityCheckerTests.cs | 8 ++--- src/Ombi.Schedule/IoCJobActivator.cs | 28 ---------------- .../Jobs/Emby/EmbyAvaliabilityChecker.cs | 2 -- .../Jobs/Emby/EmbyContentSync.cs | 3 -- .../Jobs/Emby/EmbyEpisodeSync.cs | 1 - .../Jobs/Lidarr/LidarrAlbumSync.cs | 7 ++-- .../Jobs/Lidarr/LidarrArtistSync.cs | 7 ++-- .../Jobs/Lidarr/LidarrAvailabilityChecker.cs | 7 +--- .../Ombi/Interfaces/IOmbiAutomaticUpdater.cs | 1 - .../Jobs/Ombi/MediaDatabaseRefresh.cs | 2 -- .../Jobs/Ombi/OmbiAutomaticUpdater.cs | 2 -- .../Jobs/Ombi/RefreshMetadata.cs | 4 --- .../Jobs/Plex/PlexAvailabilityChecker.cs | 7 +--- .../Jobs/Plex/PlexContentSync.cs | 1 - .../Jobs/Plex/PlexEpisodeSync.cs | 1 - src/Ombi.Schedule/Ombi.Schedule.csproj | 6 ---- src/Ombi/Controllers/IdentityController.cs | 6 ++-- src/Ombi/Controllers/IssuesController.cs | 3 -- src/Ombi/Controllers/JobController.cs | 4 --- src/Ombi/Controllers/SettingsController.cs | 3 -- src/Ombi/Ombi.csproj | 5 --- src/Ombi/Startup.cs | 33 +------------------ 25 files changed, 15 insertions(+), 130 deletions(-) delete mode 100644 src/Ombi.Schedule/IoCJobActivator.cs diff --git a/src/Ombi.Core/Ombi.Core.csproj b/src/Ombi.Core/Ombi.Core.csproj index 790aa8500..8ffbd514a 100644 --- a/src/Ombi.Core/Ombi.Core.csproj +++ b/src/Ombi.Core/Ombi.Core.csproj @@ -11,7 +11,6 @@ - diff --git a/src/Ombi.DependencyInjection/IocExtensions.cs b/src/Ombi.DependencyInjection/IocExtensions.cs index c4e66c6f5..cec6bf4e3 100644 --- a/src/Ombi.DependencyInjection/IocExtensions.cs +++ b/src/Ombi.DependencyInjection/IocExtensions.cs @@ -1,6 +1,5 @@ using System.Diagnostics.CodeAnalysis; using System.Security.Principal; -using Hangfire; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; @@ -183,7 +182,6 @@ namespace Ombi.DependencyInjection { services.AddSingleton(); services.AddSingleton(); - services.AddTransient(); services.AddTransient(); services.AddTransient(); diff --git a/src/Ombi.Schedule.Tests/OmbiQuartzTests.cs b/src/Ombi.Schedule.Tests/OmbiQuartzTests.cs index 3c728300d..b5d94c15f 100644 --- a/src/Ombi.Schedule.Tests/OmbiQuartzTests.cs +++ b/src/Ombi.Schedule.Tests/OmbiQuartzTests.cs @@ -3,6 +3,7 @@ using NUnit.Framework; using Quartz; using System.Threading; using System.Threading.Tasks; +using Ombi.Helpers; namespace Ombi.Schedule.Tests { diff --git a/src/Ombi.Schedule.Tests/PlexAvailabilityCheckerTests.cs b/src/Ombi.Schedule.Tests/PlexAvailabilityCheckerTests.cs index 028c044b7..b91ab59f6 100644 --- a/src/Ombi.Schedule.Tests/PlexAvailabilityCheckerTests.cs +++ b/src/Ombi.Schedule.Tests/PlexAvailabilityCheckerTests.cs @@ -4,9 +4,9 @@ using System.Linq; using System.Linq.Expressions; using System.Threading.Tasks; using Castle.Components.DictionaryAdapter; -using Hangfire; using Moq; using NUnit.Framework; +using Ombi.Core; using Ombi.Core.Notifications; using Ombi.Schedule.Jobs.Plex; using Ombi.Store.Entities; @@ -25,15 +25,15 @@ namespace Ombi.Schedule.Tests _repo = new Mock(); _tv = new Mock(); _movie = new Mock(); - _notify = new Mock(); - Checker = new PlexAvailabilityChecker(_repo.Object, _tv.Object, _movie.Object, _notify.Object, new Mock().Object, null); + _notify = new Mock(); + Checker = new PlexAvailabilityChecker(_repo.Object, _tv.Object, _movie.Object, _notify.Object, null); } private Mock _repo; private Mock _tv; private Mock _movie; - private Mock _notify; + private Mock _notify; private PlexAvailabilityChecker Checker; [Test] diff --git a/src/Ombi.Schedule/IoCJobActivator.cs b/src/Ombi.Schedule/IoCJobActivator.cs deleted file mode 100644 index 787ef8b6d..000000000 --- a/src/Ombi.Schedule/IoCJobActivator.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Linq; -using System.Reflection; -using Hangfire; -using Microsoft.Extensions.DependencyInjection; - -namespace Ombi.Schedule -{ - public class IoCJobActivator : JobActivator - { - private readonly IServiceProvider _container; - public IoCJobActivator(IServiceProvider container) - { - _container = container; - } - - public override object ActivateJob(Type type) - { - var scopeFactory = _container.GetService(); - var scope = scopeFactory.CreateScope(); - var scopedContainer = scope.ServiceProvider; - - var interfaceType = type.GetTypeInfo().ImplementedInterfaces.FirstOrDefault(); - var implementation = scopedContainer.GetRequiredService(interfaceType); - return implementation; - } - } -} \ No newline at end of file diff --git a/src/Ombi.Schedule/Jobs/Emby/EmbyAvaliabilityChecker.cs b/src/Ombi.Schedule/Jobs/Emby/EmbyAvaliabilityChecker.cs index ade23329d..baeb3c5c5 100644 --- a/src/Ombi.Schedule/Jobs/Emby/EmbyAvaliabilityChecker.cs +++ b/src/Ombi.Schedule/Jobs/Emby/EmbyAvaliabilityChecker.cs @@ -28,11 +28,9 @@ using System; using System.Linq; using System.Threading.Tasks; -using Hangfire; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Ombi.Core; -using Ombi.Core.Notifications; using Ombi.Helpers; using Ombi.Notifications.Models; using Ombi.Schedule.Jobs.Ombi; diff --git a/src/Ombi.Schedule/Jobs/Emby/EmbyContentSync.cs b/src/Ombi.Schedule/Jobs/Emby/EmbyContentSync.cs index 2d4b168af..34e697726 100644 --- a/src/Ombi.Schedule/Jobs/Emby/EmbyContentSync.cs +++ b/src/Ombi.Schedule/Jobs/Emby/EmbyContentSync.cs @@ -2,18 +2,15 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Hangfire; using Microsoft.Extensions.Logging; using Ombi.Api.Emby; using Ombi.Api.Emby.Models.Movie; using Ombi.Core.Settings; using Ombi.Core.Settings.Models.External; using Ombi.Helpers; -using Ombi.Schedule.Jobs.Ombi; using Ombi.Store.Entities; using Ombi.Store.Repository; using Quartz; -using Serilog; using EmbyMediaType = Ombi.Store.Entities.EmbyMediaType; namespace Ombi.Schedule.Jobs.Emby diff --git a/src/Ombi.Schedule/Jobs/Emby/EmbyEpisodeSync.cs b/src/Ombi.Schedule/Jobs/Emby/EmbyEpisodeSync.cs index 140d53b0a..1f67db4bc 100644 --- a/src/Ombi.Schedule/Jobs/Emby/EmbyEpisodeSync.cs +++ b/src/Ombi.Schedule/Jobs/Emby/EmbyEpisodeSync.cs @@ -29,7 +29,6 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Hangfire; using Microsoft.Extensions.Logging; using Ombi.Api.Emby; using Ombi.Core.Settings; diff --git a/src/Ombi.Schedule/Jobs/Lidarr/LidarrAlbumSync.cs b/src/Ombi.Schedule/Jobs/Lidarr/LidarrAlbumSync.cs index 09bd787e7..f094d3f90 100644 --- a/src/Ombi.Schedule/Jobs/Lidarr/LidarrAlbumSync.cs +++ b/src/Ombi.Schedule/Jobs/Lidarr/LidarrAlbumSync.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Hangfire; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Internal; using Microsoft.Extensions.Logging; @@ -18,13 +17,12 @@ namespace Ombi.Schedule.Jobs.Lidarr public class LidarrAlbumSync : ILidarrAlbumSync { public LidarrAlbumSync(ISettingsService lidarr, ILidarrApi lidarrApi, ILogger log, ExternalContext ctx, - IBackgroundJobClient job, ILidarrAvailabilityChecker availability) + ILidarrAvailabilityChecker availability) { _lidarrSettings = lidarr; _lidarrApi = lidarrApi; _logger = log; _ctx = ctx; - _job = job; _availability = availability; } @@ -32,7 +30,6 @@ namespace Ombi.Schedule.Jobs.Lidarr private readonly ILidarrApi _lidarrApi; private readonly ILogger _logger; private readonly ExternalContext _ctx; - private readonly IBackgroundJobClient _job; private readonly ILidarrAvailabilityChecker _availability; public async Task CacheContent() @@ -87,7 +84,7 @@ namespace Ombi.Schedule.Jobs.Lidarr _logger.LogError(LoggingEvents.Cacher, ex, "Failed caching queued items from Lidarr Album"); } - _job.Enqueue(() => _availability.Start()); + await _availability.Start(); } } catch (Exception) diff --git a/src/Ombi.Schedule/Jobs/Lidarr/LidarrArtistSync.cs b/src/Ombi.Schedule/Jobs/Lidarr/LidarrArtistSync.cs index 317b5821e..61200d0e4 100644 --- a/src/Ombi.Schedule/Jobs/Lidarr/LidarrArtistSync.cs +++ b/src/Ombi.Schedule/Jobs/Lidarr/LidarrArtistSync.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Hangfire; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Internal; using Microsoft.Extensions.Logging; @@ -19,13 +18,12 @@ namespace Ombi.Schedule.Jobs.Lidarr public class LidarrArtistSync : ILidarrArtistSync { public LidarrArtistSync(ISettingsService lidarr, ILidarrApi lidarrApi, ILogger log, ExternalContext ctx, - IBackgroundJobClient background, ILidarrAlbumSync album) + ILidarrAlbumSync album) { _lidarrSettings = lidarr; _lidarrApi = lidarrApi; _logger = log; _ctx = ctx; - _job = background; _albumSync = album; } @@ -33,7 +31,6 @@ namespace Ombi.Schedule.Jobs.Lidarr private readonly ILidarrApi _lidarrApi; private readonly ILogger _logger; private readonly ExternalContext _ctx; - private readonly IBackgroundJobClient _job; private readonly ILidarrAlbumSync _albumSync; public async Task Execute(IJobExecutionContext job) @@ -84,7 +81,7 @@ namespace Ombi.Schedule.Jobs.Lidarr _logger.LogError(LoggingEvents.Cacher, ex, "Failed caching queued items from Lidarr"); } - _job.Enqueue(() => _albumSync.CacheContent()); + await _albumSync.CacheContent(); } } catch (Exception) diff --git a/src/Ombi.Schedule/Jobs/Lidarr/LidarrAvailabilityChecker.cs b/src/Ombi.Schedule/Jobs/Lidarr/LidarrAvailabilityChecker.cs index bdc697773..37abd68a2 100644 --- a/src/Ombi.Schedule/Jobs/Lidarr/LidarrAvailabilityChecker.cs +++ b/src/Ombi.Schedule/Jobs/Lidarr/LidarrAvailabilityChecker.cs @@ -2,11 +2,9 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Hangfire; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Ombi.Core; -using Ombi.Core.Notifications; using Ombi.Helpers; using Ombi.Notifications.Models; using Ombi.Store.Entities; @@ -18,20 +16,17 @@ namespace Ombi.Schedule.Jobs.Lidarr { public class LidarrAvailabilityChecker : ILidarrAvailabilityChecker { - public LidarrAvailabilityChecker(IMusicRequestRepository requests, IRepository albums, ILogger log, - IBackgroundJobClient job, INotificationHelper notification) + public LidarrAvailabilityChecker(IMusicRequestRepository requests, IRepository albums, ILogger log, INotificationHelper notification) { _cachedAlbums = albums; _requestRepository = requests; _logger = log; - _job = job; _notificationService = notification; } private readonly IMusicRequestRepository _requestRepository; private readonly IRepository _cachedAlbums; private readonly ILogger _logger; - private readonly IBackgroundJobClient _job; private readonly INotificationHelper _notificationService; public async Task Start() diff --git a/src/Ombi.Schedule/Jobs/Ombi/Interfaces/IOmbiAutomaticUpdater.cs b/src/Ombi.Schedule/Jobs/Ombi/Interfaces/IOmbiAutomaticUpdater.cs index 484700c85..85765b6c6 100644 --- a/src/Ombi.Schedule/Jobs/Ombi/Interfaces/IOmbiAutomaticUpdater.cs +++ b/src/Ombi.Schedule/Jobs/Ombi/Interfaces/IOmbiAutomaticUpdater.cs @@ -1,5 +1,4 @@ using System.Threading.Tasks; -using Hangfire.Server; namespace Ombi.Schedule.Jobs.Ombi { diff --git a/src/Ombi.Schedule/Jobs/Ombi/MediaDatabaseRefresh.cs b/src/Ombi.Schedule/Jobs/Ombi/MediaDatabaseRefresh.cs index 9c1c8b638..6915b025d 100644 --- a/src/Ombi.Schedule/Jobs/Ombi/MediaDatabaseRefresh.cs +++ b/src/Ombi.Schedule/Jobs/Ombi/MediaDatabaseRefresh.cs @@ -1,8 +1,6 @@ using System; using System.Threading.Tasks; -using Hangfire; using Microsoft.Extensions.Logging; -using Ombi.Api.Plex; using Ombi.Core.Settings; using Ombi.Core.Settings.Models.External; using Ombi.Helpers; diff --git a/src/Ombi.Schedule/Jobs/Ombi/OmbiAutomaticUpdater.cs b/src/Ombi.Schedule/Jobs/Ombi/OmbiAutomaticUpdater.cs index 82187ed50..a6a7c5c76 100644 --- a/src/Ombi.Schedule/Jobs/Ombi/OmbiAutomaticUpdater.cs +++ b/src/Ombi.Schedule/Jobs/Ombi/OmbiAutomaticUpdater.cs @@ -9,8 +9,6 @@ using System.Reflection; using System.Runtime.InteropServices; using System.Text; using System.Threading.Tasks; -using Hangfire; -using Hangfire.Server; using Microsoft.Extensions.Logging; using Ombi.Core.Processor; using Ombi.Core.Settings; diff --git a/src/Ombi.Schedule/Jobs/Ombi/RefreshMetadata.cs b/src/Ombi.Schedule/Jobs/Ombi/RefreshMetadata.cs index 7766119cc..3cc16952f 100644 --- a/src/Ombi.Schedule/Jobs/Ombi/RefreshMetadata.cs +++ b/src/Ombi.Schedule/Jobs/Ombi/RefreshMetadata.cs @@ -1,8 +1,6 @@ using System; -using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Hangfire; using Microsoft.Extensions.Logging; using Ombi.Api.Emby; using Ombi.Api.TheMovieDb; @@ -11,8 +9,6 @@ using Ombi.Api.TvMaze; using Ombi.Core.Settings; using Ombi.Core.Settings.Models.External; using Ombi.Helpers; -using Ombi.Schedule.Jobs.Emby; -using Ombi.Schedule.Jobs.Plex; using Ombi.Store.Entities; using Ombi.Store.Repository; using Quartz; diff --git a/src/Ombi.Schedule/Jobs/Plex/PlexAvailabilityChecker.cs b/src/Ombi.Schedule/Jobs/Plex/PlexAvailabilityChecker.cs index 78fce3949..34643aa73 100644 --- a/src/Ombi.Schedule/Jobs/Plex/PlexAvailabilityChecker.cs +++ b/src/Ombi.Schedule/Jobs/Plex/PlexAvailabilityChecker.cs @@ -1,12 +1,9 @@ using System; -using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Hangfire; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Ombi.Core; -using Ombi.Core.Notifications; using Ombi.Helpers; using Ombi.Notifications.Models; using Ombi.Store.Entities; @@ -20,13 +17,12 @@ namespace Ombi.Schedule.Jobs.Plex public class PlexAvailabilityChecker : IPlexAvailabilityChecker { public PlexAvailabilityChecker(IPlexContentRepository repo, ITvRequestRepository tvRequest, IMovieRequestRepository movies, - INotificationHelper notification, IBackgroundJobClient background, ILogger log) + INotificationHelper notification, ILogger log) { _tvRepo = tvRequest; _repo = repo; _movieRepo = movies; _notificationService = notification; - _backgroundJobClient = background; _log = log; } @@ -34,7 +30,6 @@ namespace Ombi.Schedule.Jobs.Plex private readonly IMovieRequestRepository _movieRepo; private readonly IPlexContentRepository _repo; private readonly INotificationHelper _notificationService; - private readonly IBackgroundJobClient _backgroundJobClient; private readonly ILogger _log; public async Task Execute(IJobExecutionContext job) diff --git a/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs b/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs index f290f2dc9..ee16b1efd 100644 --- a/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs +++ b/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs @@ -29,7 +29,6 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Hangfire; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Ombi.Api.Plex; diff --git a/src/Ombi.Schedule/Jobs/Plex/PlexEpisodeSync.cs b/src/Ombi.Schedule/Jobs/Plex/PlexEpisodeSync.cs index dcf5ea395..fe23e9a9f 100644 --- a/src/Ombi.Schedule/Jobs/Plex/PlexEpisodeSync.cs +++ b/src/Ombi.Schedule/Jobs/Plex/PlexEpisodeSync.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Hangfire; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Ombi.Api.Plex; diff --git a/src/Ombi.Schedule/Ombi.Schedule.csproj b/src/Ombi.Schedule/Ombi.Schedule.csproj index 14d3c5197..82111d45d 100644 --- a/src/Ombi.Schedule/Ombi.Schedule.csproj +++ b/src/Ombi.Schedule/Ombi.Schedule.csproj @@ -10,12 +10,6 @@ - - - - - - diff --git a/src/Ombi/Controllers/IdentityController.cs b/src/Ombi/Controllers/IdentityController.cs index e531ee6bc..76ff4565c 100644 --- a/src/Ombi/Controllers/IdentityController.cs +++ b/src/Ombi/Controllers/IdentityController.cs @@ -4,7 +4,6 @@ using System.Linq; using System.Net; using System.Threading.Tasks; using AutoMapper; -using Hangfire; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Mvc; @@ -860,7 +859,7 @@ namespace Ombi.Controllers [HttpPost("welcomeEmail")] [PowerUser] - public void SendWelcomeEmail([FromBody] UserViewModel user) + public async Task SendWelcomeEmail([FromBody] UserViewModel user) { var ombiUser = new OmbiUser { @@ -868,7 +867,8 @@ namespace Ombi.Controllers Email = user.EmailAddress, UserName = user.UserName }; - BackgroundJob.Enqueue(() => WelcomeEmail.SendEmail(ombiUser)); + await WelcomeEmail.SendEmail(ombiUser); + return Ok(); } [HttpGet("accesstoken")] diff --git a/src/Ombi/Controllers/IssuesController.cs b/src/Ombi/Controllers/IssuesController.cs index 72d82fc25..d31aec647 100644 --- a/src/Ombi/Controllers/IssuesController.cs +++ b/src/Ombi/Controllers/IssuesController.cs @@ -6,17 +6,14 @@ using Ombi.Store.Entities.Requests; using Ombi.Store.Repository; using System.Collections.Generic; using System.Linq; -using Hangfire; using Microsoft.AspNetCore.Identity; using Microsoft.EntityFrameworkCore; using Ombi.Attributes; using Ombi.Core; -using Ombi.Core.Notifications; using Ombi.Helpers; using Ombi.Models; using Ombi.Notifications.Models; using Ombi.Store.Entities; -using StackExchange.Profiling.Helpers; namespace Ombi.Controllers { diff --git a/src/Ombi/Controllers/JobController.cs b/src/Ombi/Controllers/JobController.cs index 4171c2fa8..ab4dba5a1 100644 --- a/src/Ombi/Controllers/JobController.cs +++ b/src/Ombi/Controllers/JobController.cs @@ -1,13 +1,9 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; -using Hangfire; using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Caching.Memory; -using Ombi.Api.Service; using Ombi.Attributes; using Ombi.Helpers; -using Ombi.Schedule; using Ombi.Schedule.Jobs; using Ombi.Schedule.Jobs.Emby; using Ombi.Schedule.Jobs.Ombi; diff --git a/src/Ombi/Controllers/SettingsController.cs b/src/Ombi/Controllers/SettingsController.cs index 69dc08498..ed246806a 100644 --- a/src/Ombi/Controllers/SettingsController.cs +++ b/src/Ombi/Controllers/SettingsController.cs @@ -7,10 +7,8 @@ using System.Reflection; using System.Runtime.InteropServices; using System.Threading.Tasks; using AutoMapper; -using Hangfire; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; -using NCrontab; using Ombi.Api.Emby; using Ombi.Attributes; using Ombi.Core.Models.UI; @@ -28,7 +26,6 @@ using Ombi.Store.Repository; using Ombi.Api.Github; using Ombi.Core.Engine; using Ombi.Extensions; -using Ombi.Schedule; using Quartz; namespace Ombi.Controllers diff --git a/src/Ombi/Ombi.csproj b/src/Ombi/Ombi.csproj index a5a3ed68e..b150b0244 100644 --- a/src/Ombi/Ombi.csproj +++ b/src/Ombi/Ombi.csproj @@ -65,11 +65,6 @@ - - - - - diff --git a/src/Ombi/Startup.cs b/src/Ombi/Startup.cs index f713fe31b..56e19bb11 100755 --- a/src/Ombi/Startup.cs +++ b/src/Ombi/Startup.cs @@ -2,10 +2,6 @@ using System.IO; using AutoMapper; using AutoMapper.EquivalencyExpression; -using Hangfire; -using Hangfire.Dashboard; -using Hangfire.MemoryStorage; -using Hangfire.SQLite; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.HttpOverrides; @@ -93,13 +89,6 @@ namespace Ombi services.AddSwagger(); services.AddAppSettingsValues(Configuration); - services.AddHangfire(x => - { - x.UseMemoryStorage(); - x.UseActivator(new IoCJobActivator(services.BuildServiceProvider())); - }); - - services.AddCors(o => o.AddPolicy("MyPolicy", builder => { builder.AllowAnyOrigin() @@ -176,19 +165,7 @@ namespace Ombi app.UsePathBase(settings.BaseUrl); } - app.UseHangfireServer(new BackgroundJobServerOptions { WorkerCount = 1, ServerTimeout = TimeSpan.FromDays(1), ShutdownTimeout = TimeSpan.FromDays(1)}); - if (env.IsDevelopment()) - { - app.UseHangfireDashboard(settings.BaseUrl.HasValue() ? $"{settings.BaseUrl}/hangfire" : "/hangfire", - new DashboardOptions - { - Authorization = new[] { new HangfireAuthorizationFilter() } - }); - } - - GlobalJobFilters.Filters.Add(new AutomaticRetryAttribute { Attempts = 3 }); - - // Setup the scheduler + // Setup the scheduler //var jobSetup = app.ApplicationServices.GetService(); //jobSetup.Setup(); ctx.Seed(); @@ -233,12 +210,4 @@ namespace Ombi }); } } - - public class HangfireAuthorizationFilter : IDashboardAuthorizationFilter - { - public bool Authorize(DashboardContext context) - { - return true; - } - } } From ef5a382a1e0b5c9dbd856eedbcbfc114378d464c Mon Sep 17 00:00:00 2001 From: Jamie Date: Sun, 10 Nov 2019 19:31:33 +0000 Subject: [PATCH 05/11] Update login.component.ts Reduced oauth time --- src/Ombi/ClientApp/app/login/login.component.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Ombi/ClientApp/app/login/login.component.ts b/src/Ombi/ClientApp/app/login/login.component.ts index 957ced058..4a7d554c9 100644 --- a/src/Ombi/ClientApp/app/login/login.component.ts +++ b/src/Ombi/ClientApp/app/login/login.component.ts @@ -145,7 +145,7 @@ export class LoginComponent implements OnDestroy, OnInit { this.pinTimer = setInterval(() => { this.notify.info("Authenticating", "Loading... Please Wait"); this.getPinResult(x.pinId); - }, 10000); + }, 3000); }); }); } From 53ecd7b95fe53d436f120fb3aeabd5e473419c6b Mon Sep 17 00:00:00 2001 From: tidusjar Date: Tue, 12 Nov 2019 22:47:01 +0000 Subject: [PATCH 06/11] Fixed the issue where we couldn't always pick up stuff on the sync --- src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs | 3 --- src/Ombi.Schedule/Jobs/Plex/PlexEpisodeSync.cs | 3 ++- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs b/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs index ee16b1efd..d4cd7c040 100644 --- a/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs +++ b/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs @@ -109,9 +109,6 @@ namespace Ombi.Schedule.Jobs.Plex { Logger.LogInformation("Kicking off Plex Availability Checker"); await OmbiQuartz.TriggerJob(nameof(IPlexAvailabilityChecker), "Plex"); - Logger.LogInformation("Starting Metadata refresh"); - // Just check what we send it - await OmbiQuartz.TriggerJob(nameof(IRefreshMetadata), "System"); } Logger.LogInformation("Finished Plex Content Cacher, with processed content: {0}, episodes: {1}. Recently Added Scan: {2}", processedContent?.Content?.Count() ?? 0, processedContent?.Episodes?.Count() ?? 0, recentlyAddedSearch); diff --git a/src/Ombi.Schedule/Jobs/Plex/PlexEpisodeSync.cs b/src/Ombi.Schedule/Jobs/Plex/PlexEpisodeSync.cs index fe23e9a9f..b8829569e 100644 --- a/src/Ombi.Schedule/Jobs/Plex/PlexEpisodeSync.cs +++ b/src/Ombi.Schedule/Jobs/Plex/PlexEpisodeSync.cs @@ -9,6 +9,7 @@ using Ombi.Api.Plex.Models; using Ombi.Core.Settings; using Ombi.Core.Settings.Models.External; using Ombi.Helpers; +using Ombi.Schedule.Jobs.Ombi; using Ombi.Schedule.Jobs.Plex.Interfaces; using Ombi.Store.Entities; using Ombi.Store.Repository; @@ -54,7 +55,7 @@ namespace Ombi.Schedule.Jobs.Plex _log.LogError(LoggingEvents.Cacher, e, "Caching Episodes Failed"); } - + await OmbiQuartz.TriggerJob(nameof(IRefreshMetadata), "System"); await OmbiQuartz.TriggerJob(nameof(IPlexAvailabilityChecker), "Plex"); } From 0da0da7d86d167c874e9cc2cfb71637bca9ee6d7 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Tue, 12 Nov 2019 22:48:14 +0000 Subject: [PATCH 07/11] !changelog --- CHANGELOG.md | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a611b5b99..6febb6683 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,77 @@ # Changelog -## v3.0.4817 (2019-10-15) +## (unreleased) + +### **New Features** + +- Update login.component.ts. [Jamie] + +- Update CHANGELOG.md. [Jamie] + +- Updated SlackNotification.cs. [Tim] + +### **Fixes** + +- Fixed the issue where we couldn't always pick up stuff on the sync. [tidusjar] + +- Removed hangfire completly from Ombi. [tidusjar] + +- Fixed the notifications issue. [tidusjar] + +- Fixed the issues where the DB was being disposed too early. [tidusjar] + +- Fixed an error with the newsletter with the new db structure. [tidusjar] + +- Output some useful stuff to the about window regarding the databases. [tidusjar] + +- Fixed the migration for combined databases. [tidusjar] + +- Fixed the issue where exisitng databases would now fail due to the DB structure changes. [tidusjar] + +- Finished it! [tidusjar] + +- Got MySql working. [tidusjar] + +- Got the new DB structure in place. [tidusjar] + +- Fix for #3219. [tidusjar] + +- Fixed the error in the newsletter. [tidusjar] + +- Fixed #3208. [tidusjar] + +- Use tags and autocomplete for excluded keywords. [Taylor Buchanan] + +- Add comments to clarify filter decisions. [Taylor Buchanan] + +- Fix TS import order. [Taylor Buchanan] + +- Add adult movie filtering. [Taylor Buchanan] + +- Fix search bar overlap on mobile. [Taylor Buchanan] + +- New translations en.json (Slovak) [Jamie] + +- New translations en.json (Slovak) [Jamie] + +- New translations en.json (Slovak) [Jamie] + +- New translations en.json (Slovak) [Jamie] + +- New translations en.json (Slovak) [Jamie] + +- New translations en.json (Slovak) [Jamie] + +- New translations en.json (Slovak) [Jamie] + +- Add SK lang. [Jamie Rees] + +- Add the migration to the correct database... #3214. [tidusjar] + +- Hopefully provide a fix now for #2998 Theory is that the refresh metadata was using stale data and then overriding the availbility that just happened on that media item. [tidusjar] + + +## v3.0.4817 (2019-10-12) ### **New Features** @@ -34,6 +105,8 @@ ### **Fixes** +- Gitchangelog. [tidusjar] + - Fixed #3078. [tidusjar] - Fixes issue #3195 The new string extension method ToHttpsUrl ensures that URLs starting with "https" are no longer turned into "httpss" The commit also replaces all occurances of the error prone .Replace("http", "https") in the whole solution. [msdeibel] From 93f5f94a1467269a008eacd8d4a7e54aa730744c Mon Sep 17 00:00:00 2001 From: tidusjar Date: Tue, 12 Nov 2019 22:52:44 +0000 Subject: [PATCH 08/11] !wip --- src/Ombi.Schedule/Jobs/Plex/PlexEpisodeSync.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Ombi.Schedule/Jobs/Plex/PlexEpisodeSync.cs b/src/Ombi.Schedule/Jobs/Plex/PlexEpisodeSync.cs index b8829569e..2ba054aeb 100644 --- a/src/Ombi.Schedule/Jobs/Plex/PlexEpisodeSync.cs +++ b/src/Ombi.Schedule/Jobs/Plex/PlexEpisodeSync.cs @@ -55,7 +55,7 @@ namespace Ombi.Schedule.Jobs.Plex _log.LogError(LoggingEvents.Cacher, e, "Caching Episodes Failed"); } - await OmbiQuartz.TriggerJob(nameof(IRefreshMetadata), "System"); + //await OmbiQuartz.TriggerJob(nameof(IRefreshMetadata), "System"); await OmbiQuartz.TriggerJob(nameof(IPlexAvailabilityChecker), "Plex"); } From 58cc49d607baac74812e7803ca0602d35f280a61 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Wed, 13 Nov 2019 22:01:28 +0000 Subject: [PATCH 09/11] Fixed issues with the RequestId Migration #3244 #3253 #3249 --- .../Context/Sqlite/ExternalSqliteContext.cs | 9 +- src/Ombi.Store/Migration.txt | 2 +- .../20191113213617_RequestIdPatch.Designer.cs | 314 ++++++++++++++++++ .../20191113213617_RequestIdPatch.cs | 22 ++ .../ClientApp/app/login/login.component.ts | 2 +- 5 files changed, 346 insertions(+), 3 deletions(-) create mode 100644 src/Ombi.Store/Migrations/ExternalSqlite/20191113213617_RequestIdPatch.Designer.cs create mode 100644 src/Ombi.Store/Migrations/ExternalSqlite/20191113213617_RequestIdPatch.cs diff --git a/src/Ombi.Store/Context/Sqlite/ExternalSqliteContext.cs b/src/Ombi.Store/Context/Sqlite/ExternalSqliteContext.cs index af30920aa..fe4a93586 100644 --- a/src/Ombi.Store/Context/Sqlite/ExternalSqliteContext.cs +++ b/src/Ombi.Store/Context/Sqlite/ExternalSqliteContext.cs @@ -1,4 +1,5 @@ using System; +using Microsoft.Data.Sqlite; using Microsoft.EntityFrameworkCore; namespace Ombi.Store.Context.Sqlite @@ -13,7 +14,13 @@ namespace Ombi.Store.Context.Sqlite _created = true; Upgrade(); Database.SetCommandTimeout(60); - Database.Migrate(); + try + { + Database.Migrate(); + } + catch (SqliteException e) when (e.Message.Equals("duplicate column name: RequestId")) + { + } } diff --git a/src/Ombi.Store/Migration.txt b/src/Ombi.Store/Migration.txt index 5d1131a75..331299143 100644 --- a/src/Ombi.Store/Migration.txt +++ b/src/Ombi.Store/Migration.txt @@ -1,3 +1,3 @@ -dotnet ef migrations add Inital --context OmbiContext --startup-project ../Ombi/Ombi.csproj +dotnet ef migrations add Inital --context OmbiSqliteContext --startup-project ../Ombi/Ombi.csproj If running migrations for any db provider other than Sqlite, then ensure the database.json is pointing at the correct DB type \ No newline at end of file diff --git a/src/Ombi.Store/Migrations/ExternalSqlite/20191113213617_RequestIdPatch.Designer.cs b/src/Ombi.Store/Migrations/ExternalSqlite/20191113213617_RequestIdPatch.Designer.cs new file mode 100644 index 000000000..0183e897c --- /dev/null +++ b/src/Ombi.Store/Migrations/ExternalSqlite/20191113213617_RequestIdPatch.Designer.cs @@ -0,0 +1,314 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Ombi.Store.Context.Sqlite; + +namespace Ombi.Store.Migrations.ExternalSqlite +{ + [DbContext(typeof(ExternalSqliteContext))] + [Migration("20191113213617_RequestIdPatch")] + partial class RequestIdPatch + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "2.2.6-servicing-10079"); + + modelBuilder.Entity("Ombi.Store.Entities.CouchPotatoCache", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("TheMovieDbId"); + + b.HasKey("Id"); + + b.ToTable("CouchPotatoCache"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.EmbyContent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AddedAt"); + + b.Property("EmbyId") + .IsRequired(); + + b.Property("ImdbId"); + + b.Property("ProviderId"); + + b.Property("TheMovieDbId"); + + b.Property("Title"); + + b.Property("TvDbId"); + + b.Property("Type"); + + b.Property("Url"); + + b.HasKey("Id"); + + b.ToTable("EmbyContent"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.EmbyEpisode", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AddedAt"); + + b.Property("EmbyId"); + + b.Property("EpisodeNumber"); + + b.Property("ImdbId"); + + b.Property("ParentId"); + + b.Property("ProviderId"); + + b.Property("SeasonNumber"); + + b.Property("TheMovieDbId"); + + b.Property("Title"); + + b.Property("TvDbId"); + + b.HasKey("Id"); + + b.HasIndex("ParentId"); + + b.ToTable("EmbyEpisode"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.LidarrAlbumCache", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AddedAt"); + + b.Property("ArtistId"); + + b.Property("ForeignAlbumId"); + + b.Property("Monitored"); + + b.Property("PercentOfTracks"); + + b.Property("ReleaseDate"); + + b.Property("Title"); + + b.Property("TrackCount"); + + b.HasKey("Id"); + + b.ToTable("LidarrAlbumCache"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.LidarrArtistCache", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ArtistId"); + + b.Property("ArtistName"); + + b.Property("ForeignArtistId"); + + b.Property("Monitored"); + + b.HasKey("Id"); + + b.ToTable("LidarrArtistCache"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.PlexEpisode", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("EpisodeNumber"); + + b.Property("GrandparentKey"); + + b.Property("Key"); + + b.Property("ParentKey"); + + b.Property("SeasonNumber"); + + b.Property("Title"); + + b.HasKey("Id"); + + b.HasIndex("GrandparentKey"); + + b.ToTable("PlexEpisode"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.PlexSeasonsContent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("ParentKey"); + + b.Property("PlexContentId"); + + b.Property("PlexServerContentId"); + + b.Property("SeasonKey"); + + b.Property("SeasonNumber"); + + b.HasKey("Id"); + + b.HasIndex("PlexServerContentId"); + + b.ToTable("PlexSeasonsContent"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.PlexServerContent", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("AddedAt"); + + b.Property("ImdbId"); + + b.Property("Key"); + + b.Property("Quality"); + + b.Property("ReleaseYear"); + + b.Property("RequestId"); + + b.Property("TheMovieDbId"); + + b.Property("Title"); + + b.Property("TvDbId"); + + b.Property("Type"); + + b.Property("Url"); + + b.HasKey("Id"); + + b.ToTable("PlexServerContent"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.RadarrCache", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("HasFile"); + + b.Property("TheMovieDbId"); + + b.HasKey("Id"); + + b.ToTable("RadarrCache"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.SickRageCache", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("TvDbId"); + + b.HasKey("Id"); + + b.ToTable("SickRageCache"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.SickRageEpisodeCache", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("EpisodeNumber"); + + b.Property("SeasonNumber"); + + b.Property("TvDbId"); + + b.HasKey("Id"); + + b.ToTable("SickRageEpisodeCache"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.SonarrCache", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("TvDbId"); + + b.HasKey("Id"); + + b.ToTable("SonarrCache"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.SonarrEpisodeCache", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("EpisodeNumber"); + + b.Property("HasFile"); + + b.Property("SeasonNumber"); + + b.Property("TvDbId"); + + b.HasKey("Id"); + + b.ToTable("SonarrEpisodeCache"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.EmbyEpisode", b => + { + b.HasOne("Ombi.Store.Entities.EmbyContent", "Series") + .WithMany("Episodes") + .HasForeignKey("ParentId") + .HasPrincipalKey("EmbyId"); + }); + + modelBuilder.Entity("Ombi.Store.Entities.PlexEpisode", b => + { + b.HasOne("Ombi.Store.Entities.PlexServerContent", "Series") + .WithMany("Episodes") + .HasForeignKey("GrandparentKey") + .HasPrincipalKey("Key") + .OnDelete(DeleteBehavior.Cascade); + }); + + modelBuilder.Entity("Ombi.Store.Entities.PlexSeasonsContent", b => + { + b.HasOne("Ombi.Store.Entities.PlexServerContent") + .WithMany("Seasons") + .HasForeignKey("PlexServerContentId"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Ombi.Store/Migrations/ExternalSqlite/20191113213617_RequestIdPatch.cs b/src/Ombi.Store/Migrations/ExternalSqlite/20191113213617_RequestIdPatch.cs new file mode 100644 index 000000000..2d0622d0f --- /dev/null +++ b/src/Ombi.Store/Migrations/ExternalSqlite/20191113213617_RequestIdPatch.cs @@ -0,0 +1,22 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace Ombi.Store.Migrations.ExternalSqlite +{ + public partial class RequestIdPatch : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + + migrationBuilder.AddColumn( + name: "RequestId", + table: "PlexServerContent", + nullable: true); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/src/Ombi/ClientApp/app/login/login.component.ts b/src/Ombi/ClientApp/app/login/login.component.ts index 4a7d554c9..a5896a373 100644 --- a/src/Ombi/ClientApp/app/login/login.component.ts +++ b/src/Ombi/ClientApp/app/login/login.component.ts @@ -145,7 +145,7 @@ export class LoginComponent implements OnDestroy, OnInit { this.pinTimer = setInterval(() => { this.notify.info("Authenticating", "Loading... Please Wait"); this.getPinResult(x.pinId); - }, 3000); + }, 4000); }); }); } From 3bd9b18b33df0442a83a1acc76433d66560999e3 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Fri, 15 Nov 2019 22:47:51 +0000 Subject: [PATCH 10/11] Fixed the startup error --- src/Ombi.Store/Context/Sqlite/ExternalSqliteContext.cs | 10 +++------- .../ExternalSqlite/20191113213617_RequestIdPatch.cs | 8 ++++---- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/Ombi.Store/Context/Sqlite/ExternalSqliteContext.cs b/src/Ombi.Store/Context/Sqlite/ExternalSqliteContext.cs index fe4a93586..adbf6e017 100644 --- a/src/Ombi.Store/Context/Sqlite/ExternalSqliteContext.cs +++ b/src/Ombi.Store/Context/Sqlite/ExternalSqliteContext.cs @@ -14,13 +14,9 @@ namespace Ombi.Store.Context.Sqlite _created = true; Upgrade(); Database.SetCommandTimeout(60); - try - { - Database.Migrate(); - } - catch (SqliteException e) when (e.Message.Equals("duplicate column name: RequestId")) - { - } + + Database.Migrate(); + } diff --git a/src/Ombi.Store/Migrations/ExternalSqlite/20191113213617_RequestIdPatch.cs b/src/Ombi.Store/Migrations/ExternalSqlite/20191113213617_RequestIdPatch.cs index 2d0622d0f..29c1a4033 100644 --- a/src/Ombi.Store/Migrations/ExternalSqlite/20191113213617_RequestIdPatch.cs +++ b/src/Ombi.Store/Migrations/ExternalSqlite/20191113213617_RequestIdPatch.cs @@ -8,10 +8,10 @@ namespace Ombi.Store.Migrations.ExternalSqlite protected override void Up(MigrationBuilder migrationBuilder) { - migrationBuilder.AddColumn( - name: "RequestId", - table: "PlexServerContent", - nullable: true); + //migrationBuilder.AddColumn( + // name: "RequestId", + // table: "PlexServerContent", + // nullable: true); } protected override void Down(MigrationBuilder migrationBuilder) From faba87cdc62f3867ae78ee304d150a6c00b3785b Mon Sep 17 00:00:00 2001 From: tidusjar Date: Wed, 20 Nov 2019 21:35:04 +0000 Subject: [PATCH 11/11] Fix for #3277 --- src/Ombi.Helpers.Tests/PlexHelperTests.cs | 2 + src/Ombi.Helpers/PlexHelper.cs | 92 ++++++----------------- 2 files changed, 23 insertions(+), 71 deletions(-) diff --git a/src/Ombi.Helpers.Tests/PlexHelperTests.cs b/src/Ombi.Helpers.Tests/PlexHelperTests.cs index 8ecb3fa0a..ef1119f9f 100644 --- a/src/Ombi.Helpers.Tests/PlexHelperTests.cs +++ b/src/Ombi.Helpers.Tests/PlexHelperTests.cs @@ -39,6 +39,8 @@ namespace Ombi.Helpers.Tests yield return new TestCaseData("com.plexapp.agents.agent47://tt2543456?lang=en", ProviderIdType.Imdb).Returns("tt2543456").SetName("Unknown IMDB agent"); yield return new TestCaseData("com.plexapp.agents.agent47://456822/1/1?lang=en", ProviderIdType.TvDb).Returns("456822").SetName("Unknown TvDb agent"); yield return new TestCaseData("com.plexapp.agents.agent47://456822/999/999?lang=en", ProviderIdType.TvDb).Returns("456822").SetName("Unknown TvDb agent, large episode and season"); + yield return new TestCaseData("com.plexapp.agents.xbmcnfotv://153021/2/1?lang=xn", ProviderIdType.TvDb).Returns("153021").SetName("xmbc agent, tv episode"); + yield return new TestCaseData("com.plexapp.agents.xbmcnfotv://153021?lang=xn", ProviderIdType.TvDb).Returns("153021").SetName("xmbc agent, tv show"); } } diff --git a/src/Ombi.Helpers/PlexHelper.cs b/src/Ombi.Helpers/PlexHelper.cs index de61b8740..a25c3b14a 100644 --- a/src/Ombi.Helpers/PlexHelper.cs +++ b/src/Ombi.Helpers/PlexHelper.cs @@ -33,14 +33,15 @@ namespace Ombi.Helpers { public class PlexHelper { - private const string ImdbMatchExpression = "tt([0-9]{1,10})"; - private const string TvDbIdMatchExpression = "//[0-9]+/([0-9]{1,3})/([0-9]{1,3})"; + private const string ImdbMatchExpression = "tt([0-9]{1,10})"; + private const string TvDbIdMatchExpression = "//[0-9]+/?([0-9]{1,3})/?([0-9]{1,3})"; public static ProviderId GetProviderIdFromPlexGuid(string guid) { //com.plexapp.agents.thetvdb://269586/2/8?lang=en //com.plexapp.agents.themoviedb://390043?lang=en //com.plexapp.agents.imdb://tt2543164?lang=en + // https://github.com/tidusjar/Ombi/issues/3277 if (string.IsNullOrEmpty(guid)) { return new ProviderId(); @@ -55,7 +56,7 @@ namespace Ombi.Helpers { TheTvDb = guidSplit[1] }; - } else + } if (guid.Contains("themoviedb", CompareOptions.IgnoreCase)) { return new ProviderId @@ -63,7 +64,6 @@ namespace Ombi.Helpers TheMovieDb = guidSplit[1] }; } - else if (guid.Contains("imdb", CompareOptions.IgnoreCase)) { return new ProviderId @@ -71,74 +71,31 @@ namespace Ombi.Helpers ImdbId = guidSplit[1] }; } - else + + var imdbRegex = new Regex(ImdbMatchExpression, RegexOptions.Compiled); + var tvdbRegex = new Regex(TvDbIdMatchExpression, RegexOptions.Compiled); + var imdbMatch = imdbRegex.IsMatch(guid); + if (imdbMatch) { - var imdbRegex = new Regex(ImdbMatchExpression, RegexOptions.Compiled); - var tvdbRegex = new Regex(TvDbIdMatchExpression, RegexOptions.Compiled); - var imdbMatch = imdbRegex.IsMatch(guid); - if (imdbMatch) + return new ProviderId { - return new ProviderId - { - ImdbId = guidSplit[1] - }; - } - else + ImdbId = guidSplit[1] + }; + } + + // Check if it matches the TvDb pattern + var tvdbMatch = tvdbRegex.IsMatch(guid); + if (tvdbMatch) + { + return new ProviderId { - // Check if it matches the TvDb pattern - var tvdbMatch = tvdbRegex.IsMatch(guid); - if (tvdbMatch) - { - return new ProviderId - { - TheTvDb = guidSplit[1] - }; - } - } + TheTvDb = guidSplit[1] + }; } } return new ProviderId(); } - public static EpisodeModelHelper GetSeasonsAndEpisodesFromPlexGuid(string guid) - { - var ep = new EpisodeModelHelper(); - //com.plexapp.agents.thetvdb://269586/2/8?lang=en - //com.plexapp.agents.themoviedb://390043?lang=en - //com.plexapp.agents.imdb://tt2543164?lang=en - if (string.IsNullOrEmpty(guid)) - return null; - try - { - var guidSplit = guid.Split(new[] { '/', '?' }, StringSplitOptions.RemoveEmptyEntries); - if (guidSplit.Length > 2) - { - if (guid.Contains("thetvdb", CompareOptions.IgnoreCase)) - { - ep.ProviderId = new ProviderId {TheTvDb = guidSplit[1]}; - } - if (guid.Contains("themoviedb", CompareOptions.IgnoreCase)) - { - ep.ProviderId = new ProviderId { TheMovieDb = guidSplit[1] }; - - } - if (guid.Contains("imdb", CompareOptions.IgnoreCase)) - { - ep.ProviderId = new ProviderId { ImdbId = guidSplit[1] }; - - } - ep.SeasonNumber = int.Parse(guidSplit[2]); - ep.EpisodeNumber = int.Parse(guidSplit[3]); - } - return ep; - - } - catch (Exception) - { - return ep; - } - } - public static string GetPlexMediaUrl(string machineId, int mediaId) { var url = @@ -147,13 +104,6 @@ namespace Ombi.Helpers } } - public class EpisodeModelHelper - { - public ProviderId ProviderId { get; set; } - public int SeasonNumber { get; set; } - public int EpisodeNumber { get; set; } - } - public class ProviderId { public string TheTvDb { get; set; }