From 7514881bd8f3bf5492ef6b108c964dd191195489 Mon Sep 17 00:00:00 2001 From: Jamie Rees Date: Tue, 23 Apr 2019 14:19:01 +0100 Subject: [PATCH] Added logging into the schedule jobs, users not get feedback about what is going on! --- src/Ombi.DependencyInjection/IocExtensions.cs | 1 - src/Ombi.Schedule.Tests/IssuesPurgeTests.cs | 2 +- .../Jobs/Couchpotato/CouchPotatoSync.cs | 13 +++++++++- .../Jobs/Emby/EmbyAvaliabilityChecker.cs | 11 ++++++++- .../Jobs/Emby/EmbyContentSync.cs | 15 ++++++++++-- .../Jobs/Emby/EmbyEpisodeSync.cs | 11 ++++++++- .../Jobs/Emby/EmbyUserImporter.cs | 12 +++++++++- .../Jobs/Lidarr/ILidarrAlbumSync.cs | 4 ++-- .../Jobs/Lidarr/ILidarrAvailabilityChecker.cs | 4 ++-- .../Jobs/Lidarr/LidarrAlbumSync.cs | 21 ++++++++++++---- .../Jobs/Lidarr/LidarrArtistSync.cs | 24 ++++++++++++------- .../Jobs/Lidarr/LidarrAvailabilityChecker.cs | 15 ++++++++++-- src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs | 16 ++++++++++++- .../Jobs/Ombi/RefreshMetadata.cs | 15 +++++++++++- .../Jobs/Plex/PlexAvailabilityChecker.cs | 14 ++++++++++- .../Jobs/Plex/PlexEpisodeSync.cs | 12 +++++++++- .../Jobs/Plex/PlexUserImporter.cs | 11 ++++++++- src/Ombi.Schedule/Ombi.Schedule.csproj | 4 ++-- src/Ombi.Schedule/OmbiScheduler.cs | 2 ++ src/Ombi.Tests/Ombi.Tests.csproj | 3 ++- src/Ombi/Ombi.csproj | 2 +- 21 files changed, 177 insertions(+), 35 deletions(-) diff --git a/src/Ombi.DependencyInjection/IocExtensions.cs b/src/Ombi.DependencyInjection/IocExtensions.cs index 9f2cd8d7d..3289cd9b2 100644 --- a/src/Ombi.DependencyInjection/IocExtensions.cs +++ b/src/Ombi.DependencyInjection/IocExtensions.cs @@ -213,7 +213,6 @@ namespace Ombi.DependencyInjection services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); diff --git a/src/Ombi.Schedule.Tests/IssuesPurgeTests.cs b/src/Ombi.Schedule.Tests/IssuesPurgeTests.cs index 2bde17204..068b00b13 100644 --- a/src/Ombi.Schedule.Tests/IssuesPurgeTests.cs +++ b/src/Ombi.Schedule.Tests/IssuesPurgeTests.cs @@ -101,7 +101,7 @@ namespace Ombi.Schedule.Tests Settings.Setup(x => x.GetSettingsAsync()).ReturnsAsync(new IssueSettings { DeleteIssues = true, DaysAfterResolvedToDelete = 5 }); Repo.Setup(x => x.GetAll()).Returns(new EnumerableQuery(issues)); - await Job.Start(); + await Job.Execute(null); Assert.That(issues[0].Status, Is.Not.EqualTo(IssueStatus.Deleted)); Assert.That(issues[1].Status, Is.Not.EqualTo(IssueStatus.Deleted)); diff --git a/src/Ombi.Schedule/Jobs/Couchpotato/CouchPotatoSync.cs b/src/Ombi.Schedule/Jobs/Couchpotato/CouchPotatoSync.cs index ca848e56f..f42d910db 100644 --- a/src/Ombi.Schedule/Jobs/Couchpotato/CouchPotatoSync.cs +++ b/src/Ombi.Schedule/Jobs/Couchpotato/CouchPotatoSync.cs @@ -28,11 +28,13 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using Microsoft.AspNetCore.SignalR; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Ombi.Api.CouchPotato; using Ombi.Core.Settings; using Ombi.Helpers; +using Ombi.Hubs; using Ombi.Settings.Settings.Models.External; using Ombi.Store.Context; using Ombi.Store.Entities; @@ -43,12 +45,13 @@ namespace Ombi.Schedule.Jobs.Couchpotato public class CouchPotatoSync : ICouchPotatoSync { public CouchPotatoSync(ISettingsService cpSettings, - ICouchPotatoApi api, ILogger log, IExternalContext ctx) + ICouchPotatoApi api, ILogger log, IExternalContext ctx, IHubContext hub) { _settings = cpSettings; _api = api; _log = log; _ctx = ctx; + _notification = hub; _settings.ClearCache(); } @@ -56,6 +59,7 @@ namespace Ombi.Schedule.Jobs.Couchpotato private readonly ICouchPotatoApi _api; private readonly ILogger _log; private readonly IExternalContext _ctx; + private readonly IHubContext _notification; public async Task Execute(IJobExecutionContext job) { @@ -65,6 +69,8 @@ namespace Ombi.Schedule.Jobs.Couchpotato return; } + await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) + .SendAsync(NotificationHub.NotificationEvent, "Couch Potato Sync Started"); try { _log.LogInformation(LoggingEvents.CouchPotatoCacher, "Getting all active movies from CP"); @@ -95,10 +101,15 @@ namespace Ombi.Schedule.Jobs.Couchpotato await _ctx.CouchPotatoCache.AddRangeAsync(movieIds); await _ctx.SaveChangesAsync(); + + await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) + .SendAsync(NotificationHub.NotificationEvent, "Couch Potato Sync Finished"); } } catch (Exception e) { + await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) + .SendAsync(NotificationHub.NotificationEvent, "Couch Potato Sync Failed"); _log.LogError(LoggingEvents.CouchPotatoCacher, e, "error when trying to get movies from CP"); throw; } diff --git a/src/Ombi.Schedule/Jobs/Emby/EmbyAvaliabilityChecker.cs b/src/Ombi.Schedule/Jobs/Emby/EmbyAvaliabilityChecker.cs index 929f8d7b9..632542d34 100644 --- a/src/Ombi.Schedule/Jobs/Emby/EmbyAvaliabilityChecker.cs +++ b/src/Ombi.Schedule/Jobs/Emby/EmbyAvaliabilityChecker.cs @@ -29,10 +29,12 @@ using System; using System.Linq; using System.Threading.Tasks; using Hangfire; +using Microsoft.AspNetCore.SignalR; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Ombi.Core.Notifications; using Ombi.Helpers; +using Ombi.Hubs; using Ombi.Notifications.Models; using Ombi.Store.Entities; using Ombi.Store.Repository; @@ -44,13 +46,14 @@ namespace Ombi.Schedule.Jobs.Emby public class EmbyAvaliabilityChecker : IEmbyAvaliabilityChecker { public EmbyAvaliabilityChecker(IEmbyContentRepository repo, ITvRequestRepository t, IMovieRequestRepository m, - INotificationService n, ILogger log) + INotificationService n, ILogger log, IHubContext notification) { _repo = repo; _tvRepo = t; _movieRepo = m; _notificationService = n; _log = log; + _notification = notification; } private readonly ITvRequestRepository _tvRepo; @@ -58,11 +61,17 @@ namespace Ombi.Schedule.Jobs.Emby private readonly IEmbyContentRepository _repo; private readonly INotificationService _notificationService; private readonly ILogger _log; + private readonly IHubContext _notification; public async Task Execute(IJobExecutionContext job) { + await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) + .SendAsync(NotificationHub.NotificationEvent, "Emby Availability Checker Started"); await ProcessMovies(); await ProcessTv(); + + await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) + .SendAsync(NotificationHub.NotificationEvent, "Emby Availability Checker Finished"); } private async Task ProcessMovies() diff --git a/src/Ombi.Schedule/Jobs/Emby/EmbyContentSync.cs b/src/Ombi.Schedule/Jobs/Emby/EmbyContentSync.cs index 3f64a6505..0fc24dd81 100644 --- a/src/Ombi.Schedule/Jobs/Emby/EmbyContentSync.cs +++ b/src/Ombi.Schedule/Jobs/Emby/EmbyContentSync.cs @@ -3,12 +3,14 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Hangfire; +using Microsoft.AspNetCore.SignalR; 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.Hubs; using Ombi.Schedule.Jobs.Ombi; using Ombi.Store.Entities; using Ombi.Store.Repository; @@ -21,19 +23,20 @@ namespace Ombi.Schedule.Jobs.Emby public class EmbyContentSync : IEmbyContentSync { public EmbyContentSync(ISettingsService settings, IEmbyApi api, ILogger logger, - IEmbyContentRepository repo) + IEmbyContentRepository repo, IHubContext notification) { _logger = logger; _settings = settings; _api = api; _repo = repo; + _notification = notification; } private readonly ILogger _logger; private readonly ISettingsService _settings; private readonly IEmbyApi _api; private readonly IEmbyContentRepository _repo; - + private readonly IHubContext _notification; public async Task Execute(IJobExecutionContext job) { @@ -41,6 +44,10 @@ namespace Ombi.Schedule.Jobs.Emby if (!embySettings.Enable) return; + + await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) + .SendAsync(NotificationHub.NotificationEvent, "Emby Content Sync Started"); + foreach (var server in embySettings.Servers) { try @@ -49,10 +56,14 @@ namespace Ombi.Schedule.Jobs.Emby } catch (Exception e) { + await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) + .SendAsync(NotificationHub.NotificationEvent, "Emby Content Sync Failed"); _logger.LogError(e, "Exception when caching Emby for server {0}", server.Name); } } + await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) + .SendAsync(NotificationHub.NotificationEvent, "Emby Content Sync Finished"); // Episodes await OmbiQuartz.TriggerJob(nameof(IEmbyEpisodeSync), "Emby"); diff --git a/src/Ombi.Schedule/Jobs/Emby/EmbyEpisodeSync.cs b/src/Ombi.Schedule/Jobs/Emby/EmbyEpisodeSync.cs index e55c46d26..2c2944a55 100644 --- a/src/Ombi.Schedule/Jobs/Emby/EmbyEpisodeSync.cs +++ b/src/Ombi.Schedule/Jobs/Emby/EmbyEpisodeSync.cs @@ -30,10 +30,12 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Hangfire; +using Microsoft.AspNetCore.SignalR; using Microsoft.Extensions.Logging; using Ombi.Api.Emby; using Ombi.Core.Settings; using Ombi.Core.Settings.Models.External; +using Ombi.Hubs; using Ombi.Store.Entities; using Ombi.Store.Repository; using Quartz; @@ -42,30 +44,37 @@ namespace Ombi.Schedule.Jobs.Emby { public class EmbyEpisodeSync : IEmbyEpisodeSync { - public EmbyEpisodeSync(ISettingsService s, IEmbyApi api, ILogger l, IEmbyContentRepository repo) + public EmbyEpisodeSync(ISettingsService s, IEmbyApi api, ILogger l, IEmbyContentRepository repo + , IHubContext notification) { _api = api; _logger = l; _settings = s; _repo = repo; + _notification = notification; } private readonly ISettingsService _settings; private readonly IEmbyApi _api; private readonly ILogger _logger; private readonly IEmbyContentRepository _repo; + private readonly IHubContext _notification; public async Task Execute(IJobExecutionContext job) { var settings = await _settings.GetSettingsAsync(); + await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) + .SendAsync(NotificationHub.NotificationEvent, "Emby Episode Sync Started"); foreach (var server in settings.Servers) { await CacheEpisodes(server); } + await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) + .SendAsync(NotificationHub.NotificationEvent, "Emby Episode Sync Finished"); await OmbiQuartz.TriggerJob(nameof(IEmbyAvaliabilityChecker), "Emby"); } diff --git a/src/Ombi.Schedule/Jobs/Emby/EmbyUserImporter.cs b/src/Ombi.Schedule/Jobs/Emby/EmbyUserImporter.cs index 5cb7b368d..cd0bd0b8e 100644 --- a/src/Ombi.Schedule/Jobs/Emby/EmbyUserImporter.cs +++ b/src/Ombi.Schedule/Jobs/Emby/EmbyUserImporter.cs @@ -29,12 +29,14 @@ using System; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.SignalR; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Ombi.Api.Emby; using Ombi.Core.Settings; using Ombi.Core.Settings.Models.External; using Ombi.Helpers; +using Ombi.Hubs; using Ombi.Settings.Settings.Models; using Ombi.Store.Entities; using Quartz; @@ -44,13 +46,14 @@ namespace Ombi.Schedule.Jobs.Emby public class EmbyUserImporter : IEmbyUserImporter { public EmbyUserImporter(IEmbyApi api, UserManager um, ILogger log, - ISettingsService embySettings, ISettingsService ums) + ISettingsService embySettings, ISettingsService ums, IHubContext notification) { _api = api; _userManager = um; _log = log; _embySettings = embySettings; _userManagementSettings = ums; + _notification = notification; } private readonly IEmbyApi _api; @@ -58,6 +61,7 @@ namespace Ombi.Schedule.Jobs.Emby private readonly ILogger _log; private readonly ISettingsService _embySettings; private readonly ISettingsService _userManagementSettings; + private readonly IHubContext _notification; public async Task Execute(IJobExecutionContext job) { @@ -71,6 +75,9 @@ namespace Ombi.Schedule.Jobs.Emby { return; } + + await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) + .SendAsync(NotificationHub.NotificationEvent, "Emby User Importer Started"); var allUsers = await _userManager.Users.Where(x => x.UserType == UserType.EmbyUser).ToListAsync(); foreach (var server in settings.Servers) { @@ -148,6 +155,9 @@ namespace Ombi.Schedule.Jobs.Emby } } } + + await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) + .SendAsync(NotificationHub.NotificationEvent, "Emby User Importer Finished"); } private bool _disposed; diff --git a/src/Ombi.Schedule/Jobs/Lidarr/ILidarrAlbumSync.cs b/src/Ombi.Schedule/Jobs/Lidarr/ILidarrAlbumSync.cs index 56444b105..6c43f58c0 100644 --- a/src/Ombi.Schedule/Jobs/Lidarr/ILidarrAlbumSync.cs +++ b/src/Ombi.Schedule/Jobs/Lidarr/ILidarrAlbumSync.cs @@ -1,12 +1,12 @@ using System.Collections.Generic; using System.Threading.Tasks; using Ombi.Store.Entities; +using Quartz; namespace Ombi.Schedule.Jobs.Lidarr { - public interface ILidarrAlbumSync + public interface ILidarrAlbumSync : IJob { - Task CacheContent(); void Dispose(); Task> GetCachedContent(); } diff --git a/src/Ombi.Schedule/Jobs/Lidarr/ILidarrAvailabilityChecker.cs b/src/Ombi.Schedule/Jobs/Lidarr/ILidarrAvailabilityChecker.cs index f0c679229..7f0deb3e8 100644 --- a/src/Ombi.Schedule/Jobs/Lidarr/ILidarrAvailabilityChecker.cs +++ b/src/Ombi.Schedule/Jobs/Lidarr/ILidarrAvailabilityChecker.cs @@ -1,9 +1,9 @@ using System.Threading.Tasks; +using Quartz; namespace Ombi.Schedule.Jobs.Lidarr { - public interface ILidarrAvailabilityChecker + public interface ILidarrAvailabilityChecker : IJob { - Task Start(); } } \ No newline at end of file diff --git a/src/Ombi.Schedule/Jobs/Lidarr/LidarrAlbumSync.cs b/src/Ombi.Schedule/Jobs/Lidarr/LidarrAlbumSync.cs index 2a50b5b38..3e75a5fdb 100644 --- a/src/Ombi.Schedule/Jobs/Lidarr/LidarrAlbumSync.cs +++ b/src/Ombi.Schedule/Jobs/Lidarr/LidarrAlbumSync.cs @@ -2,15 +2,18 @@ using System.Collections.Generic; using System.Threading.Tasks; using Hangfire; +using Microsoft.AspNetCore.SignalR; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Internal; using Microsoft.Extensions.Logging; using Ombi.Api.Lidarr; using Ombi.Core.Settings; using Ombi.Helpers; +using Ombi.Hubs; using Ombi.Settings.Settings.Models.External; using Ombi.Store.Context; using Ombi.Store.Entities; +using Quartz; using ILogger = Microsoft.Extensions.Logging.ILogger; namespace Ombi.Schedule.Jobs.Lidarr @@ -18,7 +21,7 @@ namespace Ombi.Schedule.Jobs.Lidarr public class LidarrAlbumSync : ILidarrAlbumSync { public LidarrAlbumSync(ISettingsService lidarr, ILidarrApi lidarrApi, ILogger log, IExternalContext ctx, - IBackgroundJobClient job, ILidarrAvailabilityChecker availability) + IBackgroundJobClient job, ILidarrAvailabilityChecker availability, IHubContext notification) { _lidarrSettings = lidarr; _lidarrApi = lidarrApi; @@ -26,6 +29,7 @@ namespace Ombi.Schedule.Jobs.Lidarr _ctx = ctx; _job = job; _availability = availability; + _notification = notification; } private readonly ISettingsService _lidarrSettings; @@ -34,14 +38,18 @@ namespace Ombi.Schedule.Jobs.Lidarr private readonly IExternalContext _ctx; private readonly IBackgroundJobClient _job; private readonly ILidarrAvailabilityChecker _availability; - - public async Task CacheContent() + private readonly IHubContext _notification; + + public async Task Execute(IJobExecutionContext ctx) { try { var settings = await _lidarrSettings.GetSettingsAsync(); if (settings.Enabled) { + + await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) + .SendAsync(NotificationHub.NotificationEvent, "Lidarr Album Sync Started"); try { var albums = await _lidarrApi.GetAllAlbums(settings.ApiKey, settings.FullUri); @@ -75,10 +83,15 @@ namespace Ombi.Schedule.Jobs.Lidarr } catch (System.Exception ex) { + await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) + .SendAsync(NotificationHub.NotificationEvent, "Lidarr Album Sync Failed"); _logger.LogError(LoggingEvents.Cacher, ex, "Failed caching queued items from Lidarr Album"); } - _job.Enqueue(() => _availability.Start()); + await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) + .SendAsync(NotificationHub.NotificationEvent, "Lidarr Album Sync Finished"); + + await OmbiQuartz.TriggerJob(nameof(ILidarrAvailabilityChecker), "DVR"); } } catch (Exception) diff --git a/src/Ombi.Schedule/Jobs/Lidarr/LidarrArtistSync.cs b/src/Ombi.Schedule/Jobs/Lidarr/LidarrArtistSync.cs index 200c50223..3d17df2e8 100644 --- a/src/Ombi.Schedule/Jobs/Lidarr/LidarrArtistSync.cs +++ b/src/Ombi.Schedule/Jobs/Lidarr/LidarrArtistSync.cs @@ -2,12 +2,14 @@ using System.Collections.Generic; using System.Threading.Tasks; using Hangfire; +using Microsoft.AspNetCore.SignalR; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Internal; using Microsoft.Extensions.Logging; using Ombi.Api.Lidarr; using Ombi.Core.Settings; using Ombi.Helpers; +using Ombi.Hubs; using Ombi.Settings.Settings.Models.External; using Ombi.Store.Context; using Ombi.Store.Entities; @@ -18,24 +20,22 @@ namespace Ombi.Schedule.Jobs.Lidarr { public class LidarrArtistSync : ILidarrArtistSync { - public LidarrArtistSync(ISettingsService lidarr, ILidarrApi lidarrApi, ILogger log, IExternalContext ctx, - IBackgroundJobClient background, ILidarrAlbumSync album) + public LidarrArtistSync(ISettingsService lidarr, ILidarrApi lidarrApi, ILogger log, IExternalContext ctx + , IHubContext notification) { _lidarrSettings = lidarr; _lidarrApi = lidarrApi; _logger = log; _ctx = ctx; - _job = background; - _albumSync = album; + _notification = notification; } private readonly ISettingsService _lidarrSettings; private readonly ILidarrApi _lidarrApi; private readonly ILogger _logger; private readonly IExternalContext _ctx; - private readonly IBackgroundJobClient _job; - private readonly ILidarrAlbumSync _albumSync; - + private readonly IHubContext _notification; + public async Task Execute(IJobExecutionContext job) { try @@ -43,6 +43,9 @@ namespace Ombi.Schedule.Jobs.Lidarr var settings = await _lidarrSettings.GetSettingsAsync(); if (settings.Enabled) { + + await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) + .SendAsync(NotificationHub.NotificationEvent, "Lidarr Artist Sync Started"); try { var artists = await _lidarrApi.GetArtists(settings.ApiKey, settings.FullUri); @@ -72,10 +75,15 @@ namespace Ombi.Schedule.Jobs.Lidarr } catch (Exception ex) { + await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) + .SendAsync(NotificationHub.NotificationEvent, "Lidarr Artist Sync Failed"); _logger.LogError(LoggingEvents.Cacher, ex, "Failed caching queued items from Lidarr"); } - _job.Enqueue(() => _albumSync.CacheContent()); + await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) + .SendAsync(NotificationHub.NotificationEvent, "Lidarr Artist Sync Finished"); + + await OmbiQuartz.TriggerJob(nameof(ILidarrAlbumSync), "DVR"); } } catch (Exception) diff --git a/src/Ombi.Schedule/Jobs/Lidarr/LidarrAvailabilityChecker.cs b/src/Ombi.Schedule/Jobs/Lidarr/LidarrAvailabilityChecker.cs index 5708dad6c..4dbf91215 100644 --- a/src/Ombi.Schedule/Jobs/Lidarr/LidarrAvailabilityChecker.cs +++ b/src/Ombi.Schedule/Jobs/Lidarr/LidarrAvailabilityChecker.cs @@ -3,28 +3,32 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Hangfire; +using Microsoft.AspNetCore.SignalR; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Ombi.Core.Notifications; using Ombi.Helpers; +using Ombi.Hubs; using Ombi.Notifications.Models; using Ombi.Store.Entities; using Ombi.Store.Entities.Requests; using Ombi.Store.Repository; using Ombi.Store.Repository.Requests; +using Quartz; namespace Ombi.Schedule.Jobs.Lidarr { public class LidarrAvailabilityChecker : ILidarrAvailabilityChecker { public LidarrAvailabilityChecker(IMusicRequestRepository requests, IRepository albums, ILogger log, - IBackgroundJobClient job, INotificationService notification) + IBackgroundJobClient job, INotificationService notification, IHubContext notificationHub) { _cachedAlbums = albums; _requestRepository = requests; _logger = log; _job = job; _notificationService = notification; + _notification = notificationHub; } private readonly IMusicRequestRepository _requestRepository; @@ -32,9 +36,13 @@ namespace Ombi.Schedule.Jobs.Lidarr private readonly ILogger _logger; private readonly IBackgroundJobClient _job; private readonly INotificationService _notificationService; + private readonly IHubContext _notification; - public async Task Start() + public async Task Execute(IJobExecutionContext ctx) { + + await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) + .SendAsync(NotificationHub.NotificationEvent, "Lidarr Availability Check Started"); var allAlbumRequests = _requestRepository.GetAll().Include(x => x.RequestedUser).Where(x => !x.Available); var albumsToUpdate = new List(); foreach (var request in allAlbumRequests) @@ -68,6 +76,9 @@ namespace Ombi.Schedule.Jobs.Lidarr Recipient = recipient, })); } + + await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) + .SendAsync(NotificationHub.NotificationEvent, "Lidarr Availability Check Finished"); } } } diff --git a/src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs b/src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs index 84798cc61..b2faeeff3 100644 --- a/src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs +++ b/src/Ombi.Schedule/Jobs/Ombi/NewsletterJob.cs @@ -7,6 +7,7 @@ using System.Text; using System.Threading.Tasks; using MailKit; using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.SignalR; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using MimeKit; @@ -18,6 +19,7 @@ using Ombi.Api.TvMaze; using Ombi.Core.Settings; using Ombi.Core.Settings.Models.External; using Ombi.Helpers; +using Ombi.Hubs; using Ombi.Notifications; using Ombi.Notifications.Models; using Ombi.Notifications.Templates; @@ -38,7 +40,8 @@ namespace Ombi.Schedule.Jobs.Ombi ISettingsService emailSettings, INotificationTemplatesRepository templateRepo, UserManager um, ISettingsService newsletter, ILogger log, ILidarrApi lidarrApi, IRepository albumCache, ISettingsService lidarrSettings, - ISettingsService ombiSettings, ISettingsService plexSettings, ISettingsService embySettings) + ISettingsService ombiSettings, ISettingsService plexSettings, ISettingsService embySettings + , IHubContext notification) { _plex = plex; _emby = emby; @@ -58,6 +61,7 @@ namespace Ombi.Schedule.Jobs.Ombi _ombiSettings = ombiSettings; _plexSettings = plexSettings; _embySettings = embySettings; + _notification = notification; _ombiSettings.ClearCache(); _plexSettings.ClearCache(); _emailSettings.ClearCache(); @@ -82,6 +86,7 @@ namespace Ombi.Schedule.Jobs.Ombi private readonly ISettingsService _lidarrSettings; private readonly ISettingsService _plexSettings; private readonly ISettingsService _embySettings; + private readonly IHubContext _notification; public async Task Start(NewsletterSettings settings, bool test) { @@ -95,9 +100,13 @@ namespace Ombi.Schedule.Jobs.Ombi return; } + await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) + .SendAsync(NotificationHub.NotificationEvent, "Newsletter Started"); var emailSettings = await _emailSettings.GetSettingsAsync(); if (!ValidateConfiguration(emailSettings)) { + await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) + .SendAsync(NotificationHub.NotificationEvent, "Newsletter Email Settings Not Configured"); return; } @@ -284,9 +293,14 @@ namespace Ombi.Schedule.Jobs.Ombi } catch (Exception e) { + await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) + .SendAsync(NotificationHub.NotificationEvent, "Newsletter Failed"); _log.LogError(e, "Error when attempting to create newsletter"); throw; } + + await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) + .SendAsync(NotificationHub.NotificationEvent, "Newsletter Finished"); } public async Task Execute(IJobExecutionContext job) diff --git a/src/Ombi.Schedule/Jobs/Ombi/RefreshMetadata.cs b/src/Ombi.Schedule/Jobs/Ombi/RefreshMetadata.cs index e4f175855..67ef028b5 100644 --- a/src/Ombi.Schedule/Jobs/Ombi/RefreshMetadata.cs +++ b/src/Ombi.Schedule/Jobs/Ombi/RefreshMetadata.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Hangfire; +using Microsoft.AspNetCore.SignalR; using Microsoft.Extensions.Logging; using Ombi.Api.Emby; using Ombi.Api.TheMovieDb; @@ -11,6 +12,7 @@ using Ombi.Api.TvMaze; using Ombi.Core.Settings; using Ombi.Core.Settings.Models.External; using Ombi.Helpers; +using Ombi.Hubs; using Ombi.Schedule.Jobs.Emby; using Ombi.Schedule.Jobs.Plex; using Ombi.Store.Entities; @@ -23,7 +25,7 @@ namespace Ombi.Schedule.Jobs.Ombi { public RefreshMetadata(IPlexContentRepository plexRepo, IEmbyContentRepository embyRepo, ILogger log, ITvMazeApi tvApi, ISettingsService plexSettings, - IMovieDbApi movieApi, ISettingsService embySettings, IEmbyApi embyApi) + IMovieDbApi movieApi, ISettingsService embySettings, IEmbyApi embyApi, IHubContext notification) { _plexRepo = plexRepo; _embyRepo = embyRepo; @@ -33,6 +35,7 @@ namespace Ombi.Schedule.Jobs.Ombi _plexSettings = plexSettings; _embySettings = embySettings; _embyApi = embyApi; + _notification = notification; } private readonly IPlexContentRepository _plexRepo; @@ -43,10 +46,14 @@ namespace Ombi.Schedule.Jobs.Ombi private readonly ISettingsService _plexSettings; private readonly ISettingsService _embySettings; private readonly IEmbyApi _embyApi; + private readonly IHubContext _notification; public async Task Execute(IJobExecutionContext job) { _log.LogInformation("Starting the Metadata refresh"); + + await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) + .SendAsync(NotificationHub.NotificationEvent, "Metadata Refresh Started"); try { var settings = await _plexSettings.GetSettingsAsync(); @@ -64,8 +71,14 @@ namespace Ombi.Schedule.Jobs.Ombi catch (Exception e) { _log.LogError(e, "Exception when refreshing the Plex Metadata"); + + await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) + .SendAsync(NotificationHub.NotificationEvent, "Metadata Refresh Failed"); throw; } + + await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) + .SendAsync(NotificationHub.NotificationEvent, "Metadata Refresh Finished"); } public async Task ProcessPlexServerContent(IEnumerable contentIds) diff --git a/src/Ombi.Schedule/Jobs/Plex/PlexAvailabilityChecker.cs b/src/Ombi.Schedule/Jobs/Plex/PlexAvailabilityChecker.cs index 9a7a8601a..a608f2988 100644 --- a/src/Ombi.Schedule/Jobs/Plex/PlexAvailabilityChecker.cs +++ b/src/Ombi.Schedule/Jobs/Plex/PlexAvailabilityChecker.cs @@ -3,10 +3,12 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Hangfire; +using Microsoft.AspNetCore.SignalR; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Ombi.Core.Notifications; using Ombi.Helpers; +using Ombi.Hubs; using Ombi.Notifications.Models; using Ombi.Store.Entities; using Ombi.Store.Entities.Requests; @@ -19,7 +21,7 @@ namespace Ombi.Schedule.Jobs.Plex public class PlexAvailabilityChecker : IPlexAvailabilityChecker { public PlexAvailabilityChecker(IPlexContentRepository repo, ITvRequestRepository tvRequest, IMovieRequestRepository movies, - INotificationService notification, IBackgroundJobClient background, ILogger log) + INotificationService notification, IBackgroundJobClient background, ILogger log, IHubContext hub) { _tvRepo = tvRequest; _repo = repo; @@ -27,6 +29,7 @@ namespace Ombi.Schedule.Jobs.Plex _notificationService = notification; _backgroundJobClient = background; _log = log; + _notification = hub; } private readonly ITvRequestRepository _tvRepo; @@ -35,18 +38,27 @@ namespace Ombi.Schedule.Jobs.Plex private readonly INotificationService _notificationService; private readonly IBackgroundJobClient _backgroundJobClient; private readonly ILogger _log; + private readonly IHubContext _notification; public async Task Execute(IJobExecutionContext job) { try { + + await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) + .SendAsync(NotificationHub.NotificationEvent, "Plex Availability Check Started"); await ProcessMovies(); await ProcessTv(); } catch (Exception e) { + await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) + .SendAsync(NotificationHub.NotificationEvent, "Plex Availability Check Failed"); _log.LogError(e, "Exception thrown in Plex availbility checker"); } + + await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) + .SendAsync(NotificationHub.NotificationEvent, "Plex Availability Check Finished"); } private Task ProcessTv() diff --git a/src/Ombi.Schedule/Jobs/Plex/PlexEpisodeSync.cs b/src/Ombi.Schedule/Jobs/Plex/PlexEpisodeSync.cs index 7414294be..b6e54849b 100644 --- a/src/Ombi.Schedule/Jobs/Plex/PlexEpisodeSync.cs +++ b/src/Ombi.Schedule/Jobs/Plex/PlexEpisodeSync.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Hangfire; +using Microsoft.AspNetCore.SignalR; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Ombi.Api.Plex; @@ -10,6 +11,7 @@ using Ombi.Api.Plex.Models; using Ombi.Core.Settings; using Ombi.Core.Settings.Models.External; using Ombi.Helpers; +using Ombi.Hubs; using Ombi.Schedule.Jobs.Plex.Interfaces; using Ombi.Store.Entities; using Ombi.Store.Repository; @@ -20,12 +22,13 @@ namespace Ombi.Schedule.Jobs.Plex public class PlexEpisodeSync : IPlexEpisodeSync { public PlexEpisodeSync(ISettingsService s, ILogger log, IPlexApi plexApi, - IPlexContentRepository repo) + IPlexContentRepository repo, IHubContext hub) { _settings = s; _log = log; _api = plexApi; _repo = repo; + _notification = hub; _settings.ClearCache(); } @@ -33,6 +36,7 @@ namespace Ombi.Schedule.Jobs.Plex private readonly ILogger _log; private readonly IPlexApi _api; private readonly IPlexContentRepository _repo; + private readonly IHubContext _notification; public async Task Execute(IJobExecutionContext job) { @@ -43,6 +47,8 @@ namespace Ombi.Schedule.Jobs.Plex { return; } + await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) + .SendAsync(NotificationHub.NotificationEvent, "Plex Episode Sync Started"); foreach (var server in s.Servers) { @@ -52,11 +58,15 @@ namespace Ombi.Schedule.Jobs.Plex } catch (Exception e) { + await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) + .SendAsync(NotificationHub.NotificationEvent, "Plex Episode Sync Failed"); _log.LogError(LoggingEvents.Cacher, e, "Caching Episodes Failed"); } await OmbiQuartz.TriggerJob(nameof(IPlexAvailabilityChecker), "Plex"); + await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) + .SendAsync(NotificationHub.NotificationEvent, "Plex Episode Sync Finished"); } private async Task Cache(PlexServers settings) diff --git a/src/Ombi.Schedule/Jobs/Plex/PlexUserImporter.cs b/src/Ombi.Schedule/Jobs/Plex/PlexUserImporter.cs index 7d30d780a..5451e80a8 100644 --- a/src/Ombi.Schedule/Jobs/Plex/PlexUserImporter.cs +++ b/src/Ombi.Schedule/Jobs/Plex/PlexUserImporter.cs @@ -3,12 +3,14 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Identity; +using Microsoft.AspNetCore.SignalR; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Ombi.Api.Plex; using Ombi.Core.Settings; using Ombi.Core.Settings.Models.External; using Ombi.Helpers; +using Ombi.Hubs; using Ombi.Settings.Settings.Models; using Ombi.Store.Entities; using Quartz; @@ -18,13 +20,14 @@ namespace Ombi.Schedule.Jobs.Plex public class PlexUserImporter : IPlexUserImporter { public PlexUserImporter(IPlexApi api, UserManager um, ILogger log, - ISettingsService plexSettings, ISettingsService ums) + ISettingsService plexSettings, ISettingsService ums, IHubContext hub) { _api = api; _userManager = um; _log = log; _plexSettings = plexSettings; _userManagementSettings = ums; + _notification = hub; _plexSettings.ClearCache(); _userManagementSettings.ClearCache(); } @@ -34,6 +37,7 @@ namespace Ombi.Schedule.Jobs.Plex private readonly ILogger _log; private readonly ISettingsService _plexSettings; private readonly ISettingsService _userManagementSettings; + private readonly IHubContext _notification; public async Task Execute(IJobExecutionContext job) @@ -50,6 +54,8 @@ namespace Ombi.Schedule.Jobs.Plex } + await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) + .SendAsync(NotificationHub.NotificationEvent, "Plex User Importer Started"); var allUsers = await _userManager.Users.Where(x => x.UserType == UserType.PlexUser).ToListAsync(); foreach (var server in settings.Servers) { @@ -121,6 +127,9 @@ namespace Ombi.Schedule.Jobs.Plex } } } + + await _notification.Clients.Clients(NotificationHub.AdminConnectionIds) + .SendAsync(NotificationHub.NotificationEvent, "Plex User Importer Finished"); } private async Task ImportAdmin(UserManagementSettings settings, PlexServers server, List allUsers) diff --git a/src/Ombi.Schedule/Ombi.Schedule.csproj b/src/Ombi.Schedule/Ombi.Schedule.csproj index f92b7a98b..b07f1641c 100644 --- a/src/Ombi.Schedule/Ombi.Schedule.csproj +++ b/src/Ombi.Schedule/Ombi.Schedule.csproj @@ -10,8 +10,8 @@ - - + + diff --git a/src/Ombi.Schedule/OmbiScheduler.cs b/src/Ombi.Schedule/OmbiScheduler.cs index 4ef5459dd..1f7920abb 100644 --- a/src/Ombi.Schedule/OmbiScheduler.cs +++ b/src/Ombi.Schedule/OmbiScheduler.cs @@ -76,6 +76,8 @@ namespace Ombi.Schedule await OmbiQuartz.Instance.AddJob(nameof(ICouchPotatoSync), "DVR", JobSettingsHelper.CouchPotato(s)); await OmbiQuartz.Instance.AddJob(nameof(ISickRageSync), "DVR", JobSettingsHelper.SickRageSync(s)); await OmbiQuartz.Instance.AddJob(nameof(ILidarrArtistSync), "DVR", JobSettingsHelper.LidarrArtistSync(s)); + await OmbiQuartz.Instance.AddJob(nameof(ILidarrAlbumSync), "DVR", null); + await OmbiQuartz.Instance.AddJob(nameof(ILidarrAvailabilityChecker), "DVR", null); } private static async Task AddPlex(JobSettings s) diff --git a/src/Ombi.Tests/Ombi.Tests.csproj b/src/Ombi.Tests/Ombi.Tests.csproj index 4eb65deeb..f8fd0bf24 100644 --- a/src/Ombi.Tests/Ombi.Tests.csproj +++ b/src/Ombi.Tests/Ombi.Tests.csproj @@ -1,4 +1,4 @@ - + netcoreapp2.2 @@ -10,6 +10,7 @@ + diff --git a/src/Ombi/Ombi.csproj b/src/Ombi/Ombi.csproj index 12b1da5fa..2ed1edfd2 100644 --- a/src/Ombi/Ombi.csproj +++ b/src/Ombi/Ombi.csproj @@ -57,7 +57,7 @@ - +