From c3c0228b4557ed3208f666db5d8e6b5c77dd0eda Mon Sep 17 00:00:00 2001 From: Jamie Rees Date: Thu, 11 Apr 2019 12:56:32 +0100 Subject: [PATCH] swap out the scheduler #2750 --- src/Ombi.Schedule.Tests/IssuesPurgeTests.cs | 6 +-- src/Ombi.Schedule.Tests/OmbiQuartzTests.cs | 36 +++++++++++++ .../PlexAvailabilityCheckerTests.cs | 8 +-- .../Jobs/Emby/EmbyContentSync.cs | 10 ++-- .../Jobs/Emby/EmbyEpisodeSync.cs | 9 ++-- .../Jobs/Ombi/MediaDatabaseRefresh.cs | 6 +-- .../Jobs/Ombi/RefreshMetadata.cs | 11 ++-- .../Jobs/Plex/PlexContentSync.cs | 10 ++-- .../Jobs/Plex/PlexEpisodeSync.cs | 6 +-- src/Ombi.Schedule/OmbiQuartz.cs | 19 ++++--- src/Ombi.Schedule/OmbiScheduler.cs | 53 ++++++++++--------- src/Ombi/Controllers/JobController.cs | 21 ++++---- src/Ombi/Controllers/SettingsController.cs | 7 ++- src/Ombi/Startup.cs | 2 +- 14 files changed, 117 insertions(+), 87 deletions(-) create mode 100644 src/Ombi.Schedule.Tests/OmbiQuartzTests.cs diff --git a/src/Ombi.Schedule.Tests/IssuesPurgeTests.cs b/src/Ombi.Schedule.Tests/IssuesPurgeTests.cs index 932022cd8..1606cb2d5 100644 --- a/src/Ombi.Schedule.Tests/IssuesPurgeTests.cs +++ b/src/Ombi.Schedule.Tests/IssuesPurgeTests.cs @@ -32,7 +32,7 @@ namespace Ombi.Schedule.Tests [Test] public async Task DoesNotRun_WhenDisabled() { - await Job.Start(); + await Job.Execute(null); Repo.Verify(x => x.GetAll(),Times.Never); } @@ -50,7 +50,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.First().Status, Is.EqualTo(IssueStatus.Deleted)); Repo.Verify(x => x.SaveChangesAsync(), Times.Once); @@ -75,7 +75,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.EqualTo(IssueStatus.Deleted)); diff --git a/src/Ombi.Schedule.Tests/OmbiQuartzTests.cs b/src/Ombi.Schedule.Tests/OmbiQuartzTests.cs new file mode 100644 index 000000000..a8136a5ce --- /dev/null +++ b/src/Ombi.Schedule.Tests/OmbiQuartzTests.cs @@ -0,0 +1,36 @@ +using Moq; +using NUnit.Framework; +using Quartz; +using System.Threading; +using System.Threading.Tasks; + +namespace Ombi.Schedule.Tests +{ + [TestFixture] + public class OmbiQuartzTests + { + + [Test] + [Ignore("Cannot get this to work")] + public async Task Test() + { + var scheduleMock = new Mock(); + scheduleMock.Setup(x => x.TriggerJob(It.IsAny(), + It.IsAny())); + var sut = new QuartzMock(scheduleMock); + + await QuartzMock.TriggerJob("ABC"); + + scheduleMock.Verify(x => x.TriggerJob(It.Is(j => j.Name == "ABC"), + default(CancellationToken)), Times.Once); + } + } + public class QuartzMock : OmbiQuartz + { + public QuartzMock(Mock mock) + { + _instance = this; + _scheduler = mock.Object; + } + } +} diff --git a/src/Ombi.Schedule.Tests/PlexAvailabilityCheckerTests.cs b/src/Ombi.Schedule.Tests/PlexAvailabilityCheckerTests.cs index 55c9dc288..028c044b7 100644 --- a/src/Ombi.Schedule.Tests/PlexAvailabilityCheckerTests.cs +++ b/src/Ombi.Schedule.Tests/PlexAvailabilityCheckerTests.cs @@ -46,7 +46,7 @@ namespace Ombi.Schedule.Tests _movie.Setup(x => x.GetAll()).Returns(new List { request }.AsQueryable()); _repo.Setup(x => x.Get("test")).ReturnsAsync(new PlexServerContent()); - await Checker.Start(); + await Checker.Execute(null); _movie.Verify(x => x.Save(), Times.Once); @@ -62,8 +62,8 @@ namespace Ombi.Schedule.Tests }; _movie.Setup(x => x.GetAll()).Returns(new List { request }.AsQueryable()); - await Checker.Start(); - + await Checker.Execute(null); + Assert.False(request.Available); } @@ -107,7 +107,7 @@ namespace Ombi.Schedule.Tests }.AsQueryable); _repo.Setup(x => x.Include(It.IsAny>(),It.IsAny>>())); - await Checker.Start(); + await Checker.Execute(null); _tv.Verify(x => x.Save(), Times.Once); diff --git a/src/Ombi.Schedule/Jobs/Emby/EmbyContentSync.cs b/src/Ombi.Schedule/Jobs/Emby/EmbyContentSync.cs index 656719a1f..3e1e750ae 100644 --- a/src/Ombi.Schedule/Jobs/Emby/EmbyContentSync.cs +++ b/src/Ombi.Schedule/Jobs/Emby/EmbyContentSync.cs @@ -21,22 +21,18 @@ namespace Ombi.Schedule.Jobs.Emby public class EmbyContentSync : IEmbyContentSync { public EmbyContentSync(ISettingsService settings, IEmbyApi api, ILogger logger, - IEmbyContentRepository repo, IEmbyEpisodeSync epSync, IRefreshMetadata metadata) + IEmbyContentRepository repo) { _logger = logger; _settings = settings; _api = api; _repo = repo; - _episodeSync = epSync; - _metadata = metadata; } private readonly ILogger _logger; private readonly ISettingsService _settings; private readonly IEmbyApi _api; private readonly IEmbyContentRepository _repo; - private readonly IEmbyEpisodeSync _episodeSync; - private readonly IRefreshMetadata _metadata; public async Task Execute(IJobExecutionContext job) @@ -58,6 +54,10 @@ namespace Ombi.Schedule.Jobs.Emby } // Episodes + + await OmbiQuartz.TriggerJob(nameof(IEmbyEpisodeSync)); + + await OmbiQuartz.TriggerJob(nameof(IRefreshMetadata)); //BackgroundJob.Enqueue(() => _episodeSync.Start()); //BackgroundJob.Enqueue(() => _metadata.Start()); } diff --git a/src/Ombi.Schedule/Jobs/Emby/EmbyEpisodeSync.cs b/src/Ombi.Schedule/Jobs/Emby/EmbyEpisodeSync.cs index 82dbb06a0..00a1b7da4 100644 --- a/src/Ombi.Schedule/Jobs/Emby/EmbyEpisodeSync.cs +++ b/src/Ombi.Schedule/Jobs/Emby/EmbyEpisodeSync.cs @@ -42,21 +42,18 @@ namespace Ombi.Schedule.Jobs.Emby { public class EmbyEpisodeSync : IEmbyEpisodeSync { - public EmbyEpisodeSync(ISettingsService s, IEmbyApi api, ILogger l, IEmbyContentRepository repo, - IEmbyAvaliabilityChecker checker) + public EmbyEpisodeSync(ISettingsService s, IEmbyApi api, ILogger l, IEmbyContentRepository repo) { _api = api; _logger = l; _settings = s; _repo = repo; - _avaliabilityChecker = checker; } private readonly ISettingsService _settings; private readonly IEmbyApi _api; private readonly ILogger _logger; private readonly IEmbyContentRepository _repo; - private readonly IEmbyAvaliabilityChecker _avaliabilityChecker; public async Task Execute(IJobExecutionContext job) @@ -68,7 +65,8 @@ namespace Ombi.Schedule.Jobs.Emby await CacheEpisodes(server); } - //BackgroundJob.Enqueue(() => _avaliabilityChecker.Start()); + + await OmbiQuartz.TriggerJob(nameof(IEmbyAvaliabilityChecker)); } private async Task CacheEpisodes(EmbyServers server) @@ -143,7 +141,6 @@ namespace Ombi.Schedule.Jobs.Emby { _settings?.Dispose(); _repo?.Dispose(); - _avaliabilityChecker?.Dispose(); } _disposed = true; } diff --git a/src/Ombi.Schedule/Jobs/Ombi/MediaDatabaseRefresh.cs b/src/Ombi.Schedule/Jobs/Ombi/MediaDatabaseRefresh.cs index 8dc8fcf1f..82f4ec883 100644 --- a/src/Ombi.Schedule/Jobs/Ombi/MediaDatabaseRefresh.cs +++ b/src/Ombi.Schedule/Jobs/Ombi/MediaDatabaseRefresh.cs @@ -16,13 +16,12 @@ namespace Ombi.Schedule.Jobs.Ombi public class MediaDatabaseRefresh : IMediaDatabaseRefresh { public MediaDatabaseRefresh(ISettingsService s, ILogger log, - IPlexContentRepository plexRepo, IEmbyContentRepository embyRepo, IEmbyContentSync embySync) + IPlexContentRepository plexRepo, IEmbyContentRepository embyRepo) { _settings = s; _log = log; _plexRepo = plexRepo; _embyRepo = embyRepo; - _embyContentSync = embySync; _settings.ClearCache(); } @@ -30,7 +29,6 @@ namespace Ombi.Schedule.Jobs.Ombi private readonly ILogger _log; private readonly IPlexContentRepository _plexRepo; private readonly IEmbyContentRepository _embyRepo; - private readonly IEmbyContentSync _embyContentSync; public async Task Execute(IJobExecutionContext job) { @@ -61,7 +59,7 @@ namespace Ombi.Schedule.Jobs.Ombi await _embyRepo.ExecuteSql(episodeSQL); await _embyRepo.ExecuteSql(mainSql); - //BackgroundJob.Enqueue(() => _embyContentSync.Start()); // TODO + await OmbiQuartz.TriggerJob(nameof(IEmbyContentSync)); } catch (Exception e) { diff --git a/src/Ombi.Schedule/Jobs/Ombi/RefreshMetadata.cs b/src/Ombi.Schedule/Jobs/Ombi/RefreshMetadata.cs index b1240593d..a2cebb36c 100644 --- a/src/Ombi.Schedule/Jobs/Ombi/RefreshMetadata.cs +++ b/src/Ombi.Schedule/Jobs/Ombi/RefreshMetadata.cs @@ -23,8 +23,7 @@ namespace Ombi.Schedule.Jobs.Ombi { public RefreshMetadata(IPlexContentRepository plexRepo, IEmbyContentRepository embyRepo, ILogger log, ITvMazeApi tvApi, ISettingsService plexSettings, - IMovieDbApi movieApi, ISettingsService embySettings, IPlexAvailabilityChecker plexAvailability, IEmbyAvaliabilityChecker embyAvaliability, - IEmbyApi embyApi) + IMovieDbApi movieApi, ISettingsService embySettings, IEmbyApi embyApi) { _plexRepo = plexRepo; _embyRepo = embyRepo; @@ -33,15 +32,11 @@ namespace Ombi.Schedule.Jobs.Ombi _tvApi = tvApi; _plexSettings = plexSettings; _embySettings = embySettings; - _plexAvailabilityChecker = plexAvailability; - _embyAvaliabilityChecker = embyAvaliability; _embyApi = embyApi; } private readonly IPlexContentRepository _plexRepo; private readonly IEmbyContentRepository _embyRepo; - private readonly IPlexAvailabilityChecker _plexAvailabilityChecker; - private readonly IEmbyAvaliabilityChecker _embyAvaliabilityChecker; private readonly ILogger _log; private readonly IMovieDbApi _movieApi; private readonly ITvMazeApi _tvApi; @@ -94,12 +89,12 @@ namespace Ombi.Schedule.Jobs.Ombi { if (plexSettings.Enable) { - //BackgroundJob.Enqueue(() => _plexAvailabilityChecker.Start()); // TODO + await OmbiQuartz.TriggerJob(nameof(IPlexAvailabilityChecker)); } if (embySettings.Enable) { - //BackgroundJob.Enqueue(() => _embyAvaliabilityChecker.Start()); // TODO + await OmbiQuartz.TriggerJob(nameof(IEmbyAvaliabilityChecker)); } } diff --git a/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs b/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs index add1a9674..f1c35abdb 100644 --- a/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs +++ b/src/Ombi.Schedule/Jobs/Plex/PlexContentSync.cs @@ -49,7 +49,7 @@ namespace Ombi.Schedule.Jobs.Plex public class PlexContentSync : IPlexContentSync { public PlexContentSync(ISettingsService plex, IPlexApi plexApi, ILogger logger, IPlexContentRepository repo, - IPlexEpisodeSync epsiodeSync, IRefreshMetadata metadataRefresh, IPlexAvailabilityChecker checker) + IPlexEpisodeSync epsiodeSync, IRefreshMetadata metadataRefresh) { Plex = plex; PlexApi = plexApi; @@ -57,7 +57,6 @@ namespace Ombi.Schedule.Jobs.Plex Repo = repo; EpisodeSync = epsiodeSync; Metadata = metadataRefresh; - Checker = checker; Plex.ClearCache(); } @@ -67,7 +66,6 @@ namespace Ombi.Schedule.Jobs.Plex private IPlexContentRepository Repo { get; } private IPlexEpisodeSync EpisodeSync { get; } private IRefreshMetadata Metadata { get; } - private IPlexAvailabilityChecker Checker { get; } public async Task Execute(IJobExecutionContext context) { @@ -105,7 +103,8 @@ namespace Ombi.Schedule.Jobs.Plex if (!recentlyAddedSearch) { Logger.LogInformation("Starting EP Cacher"); - //BackgroundJob.Enqueue(() => EpisodeSync.Start()); //TODO + + await OmbiQuartz.TriggerJob(nameof(IPlexEpisodeSync)); } if ((processedContent?.HasProcessedContent ?? false) && recentlyAddedSearch) @@ -116,7 +115,8 @@ namespace Ombi.Schedule.Jobs.Plex if ((processedContent?.HasProcessedEpisodes ?? false) && recentlyAddedSearch) { - //BackgroundJob.Enqueue(() => Checker.Start()); // TODO + + await OmbiQuartz.TriggerJob(nameof(IPlexAvailabilityChecker)); } } diff --git a/src/Ombi.Schedule/Jobs/Plex/PlexEpisodeSync.cs b/src/Ombi.Schedule/Jobs/Plex/PlexEpisodeSync.cs index 7e751d0d9..433051e43 100644 --- a/src/Ombi.Schedule/Jobs/Plex/PlexEpisodeSync.cs +++ b/src/Ombi.Schedule/Jobs/Plex/PlexEpisodeSync.cs @@ -20,13 +20,12 @@ namespace Ombi.Schedule.Jobs.Plex public class PlexEpisodeSync : IPlexEpisodeSync { public PlexEpisodeSync(ISettingsService s, ILogger log, IPlexApi plexApi, - IPlexContentRepository repo, IPlexAvailabilityChecker a) + IPlexContentRepository repo) { _settings = s; _log = log; _api = plexApi; _repo = repo; - _availabilityChecker = a; _settings.ClearCache(); } @@ -34,7 +33,6 @@ namespace Ombi.Schedule.Jobs.Plex private readonly ILogger _log; private readonly IPlexApi _api; private readonly IPlexContentRepository _repo; - private readonly IPlexAvailabilityChecker _availabilityChecker; public async Task Execute(IJobExecutionContext job) { @@ -57,6 +55,8 @@ namespace Ombi.Schedule.Jobs.Plex _log.LogError(LoggingEvents.Cacher, e, "Caching Episodes Failed"); } + + await OmbiQuartz.TriggerJob(nameof(IPlexAvailabilityChecker)); //BackgroundJob.Enqueue(() => _availabilityChecker.Start()); // TODO } diff --git a/src/Ombi.Schedule/OmbiQuartz.cs b/src/Ombi.Schedule/OmbiQuartz.cs index de9209738..1eb509b08 100644 --- a/src/Ombi.Schedule/OmbiQuartz.cs +++ b/src/Ombi.Schedule/OmbiQuartz.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using System.Threading.Tasks; using Quartz; using Quartz.Impl; using Quartz.Spi; @@ -7,19 +8,19 @@ namespace Ombi.Schedule { public class OmbiQuartz { - private IScheduler _scheduler; + protected IScheduler _scheduler { get; set; } public static IScheduler Scheduler => Instance._scheduler; // Singleton - private static OmbiQuartz _instance; + protected static OmbiQuartz _instance; /// /// Singleton /// public static OmbiQuartz Instance => _instance ?? (_instance = new OmbiQuartz()); - private OmbiQuartz() + protected OmbiQuartz() { Init(); } @@ -35,7 +36,7 @@ namespace Ombi.Schedule return Scheduler; } - public async void AddJob(string name, string group, string cronExpression, Dictionary jobData = null) + public async Task AddJob(string name, string group, string cronExpression, Dictionary jobData = null) where T : IJob { var jobBuilder = JobBuilder.Create() @@ -52,16 +53,18 @@ namespace Ombi.Schedule ITrigger jobTrigger = TriggerBuilder.Create() .WithIdentity(name + "Trigger", group) - - .StartNow() - .WithCronSchedule(cronExpression) .Build(); await Scheduler.ScheduleJob(job, jobTrigger); } + + public static async Task TriggerJob(string jobName) + { + await Scheduler.TriggerJob(new JobKey(jobName)); + } - public static async void Start() + public static async Task Start() { await Scheduler.Start(); } diff --git a/src/Ombi.Schedule/OmbiScheduler.cs b/src/Ombi.Schedule/OmbiScheduler.cs index 17b68fdd9..0e000ad46 100644 --- a/src/Ombi.Schedule/OmbiScheduler.cs +++ b/src/Ombi.Schedule/OmbiScheduler.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading.Tasks; using Microsoft.AspNetCore.Builder; using Ombi.Core.Settings; using Ombi.Schedule.Jobs; @@ -38,7 +39,7 @@ namespace Ombi.Schedule // .Build(); //} - public static void UseQuartz(this IApplicationBuilder app) + public static async Task UseQuartz(this IApplicationBuilder app) { // Job Factory through IOC container var jobFactory = (IJobFactory)app.ApplicationServices.GetService(typeof(IJobFactory)); @@ -48,47 +49,47 @@ namespace Ombi.Schedule OmbiQuartz.Instance.UseJobFactory(jobFactory); // Run Quartz - OmbiQuartz.Start(); + await OmbiQuartz.Start(); // Run configuration - AddPlex(s); - AddEmby(s); - AddDvrApps(s); - AddSystem(s); + await AddPlex(s); + await AddEmby(s); + await AddDvrApps(s); + await AddSystem(s); } - private static void AddSystem(JobSettings s) + private static async Task AddSystem(JobSettings s) { - OmbiQuartz.Instance.AddJob(nameof(IRefreshMetadata), "System", JobSettingsHelper.RefreshMetadata(s)); - OmbiQuartz.Instance.AddJob(nameof(IIssuesPurge), "System", JobSettingsHelper.IssuePurge(s)); + await OmbiQuartz.Instance.AddJob(nameof(IRefreshMetadata), "System", JobSettingsHelper.RefreshMetadata(s)); + await OmbiQuartz.Instance.AddJob(nameof(IIssuesPurge), "System", JobSettingsHelper.IssuePurge(s)); //OmbiQuartz.Instance.AddJob(nameof(IOmbiAutomaticUpdater), "System", JobSettingsHelper.Updater(s)); - OmbiQuartz.Instance.AddJob(nameof(INewsletterJob), "System", JobSettingsHelper.Newsletter(s)); - OmbiQuartz.Instance.AddJob(nameof(IResendFailedRequests), "System", JobSettingsHelper.ResendFailedRequests(s)); - OmbiQuartz.Instance.AddJob(nameof(IMediaDatabaseRefresh), "System", JobSettingsHelper.MediaDatabaseRefresh(s)); + await OmbiQuartz.Instance.AddJob(nameof(INewsletterJob), "System", JobSettingsHelper.Newsletter(s)); + await OmbiQuartz.Instance.AddJob(nameof(IResendFailedRequests), "System", JobSettingsHelper.ResendFailedRequests(s)); + await OmbiQuartz.Instance.AddJob(nameof(IMediaDatabaseRefresh), "System", JobSettingsHelper.MediaDatabaseRefresh(s)); } - private static void AddDvrApps(JobSettings s) + private static async Task AddDvrApps(JobSettings s) { - OmbiQuartz.Instance.AddJob(nameof(ISonarrSync), "DVR", JobSettingsHelper.Sonarr(s)); - OmbiQuartz.Instance.AddJob(nameof(IRadarrSync), "DVR", JobSettingsHelper.Radarr(s)); - OmbiQuartz.Instance.AddJob(nameof(ICouchPotatoSync), "DVR", JobSettingsHelper.CouchPotato(s)); - OmbiQuartz.Instance.AddJob(nameof(ISickRageSync), "DVR", JobSettingsHelper.SickRageSync(s)); - OmbiQuartz.Instance.AddJob(nameof(ILidarrArtistSync), "DVR", JobSettingsHelper.LidarrArtistSync(s)); + await OmbiQuartz.Instance.AddJob(nameof(ISonarrSync), "DVR", JobSettingsHelper.Sonarr(s)); + await OmbiQuartz.Instance.AddJob(nameof(IRadarrSync), "DVR", JobSettingsHelper.Radarr(s)); + 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)); } - private static void AddPlex(JobSettings s) + private static async Task AddPlex(JobSettings s) { - OmbiQuartz.Instance.AddJob(nameof(IPlexContentSync), "Plex", JobSettingsHelper.PlexContent(s), new Dictionary { { "recentlyAddedSearch", "false" } }); - OmbiQuartz.Instance.AddJob(nameof(IPlexContentSync) + "RecentlyAdded", "Plex", JobSettingsHelper.PlexContent(s), new Dictionary { { "recentlyAddedSearch", "true" } }); - OmbiQuartz.Instance.AddJob(nameof(IPlexRecentlyAddedSync), "Plex", JobSettingsHelper.PlexRecentlyAdded(s)); - OmbiQuartz.Instance.AddJob(nameof(IPlexUserImporter), "Plex", JobSettingsHelper.UserImporter(s)); + await OmbiQuartz.Instance.AddJob(nameof(IPlexContentSync), "Plex", JobSettingsHelper.PlexContent(s), new Dictionary { { "recentlyAddedSearch", "false" } }); + await OmbiQuartz.Instance.AddJob(nameof(IPlexContentSync) + "RecentlyAdded", "Plex", JobSettingsHelper.PlexContent(s), new Dictionary { { "recentlyAddedSearch", "true" } }); + await OmbiQuartz.Instance.AddJob(nameof(IPlexRecentlyAddedSync), "Plex", JobSettingsHelper.PlexRecentlyAdded(s)); + await OmbiQuartz.Instance.AddJob(nameof(IPlexUserImporter), "Plex", JobSettingsHelper.UserImporter(s)); } - private static void AddEmby(JobSettings s) + private static async Task AddEmby(JobSettings s) { - OmbiQuartz.Instance.AddJob(nameof(IEmbyContentSync), "Emby", JobSettingsHelper.EmbyContent(s)); - OmbiQuartz.Instance.AddJob(nameof(IEmbyUserImporter), "Emby", JobSettingsHelper.UserImporter(s)); + await OmbiQuartz.Instance.AddJob(nameof(IEmbyContentSync), "Emby", JobSettingsHelper.EmbyContent(s)); + await OmbiQuartz.Instance.AddJob(nameof(IEmbyUserImporter), "Emby", JobSettingsHelper.UserImporter(s)); } } } \ No newline at end of file diff --git a/src/Ombi/Controllers/JobController.cs b/src/Ombi/Controllers/JobController.cs index 42f332af4..e9fd987ba 100644 --- a/src/Ombi/Controllers/JobController.cs +++ b/src/Ombi/Controllers/JobController.cs @@ -48,9 +48,10 @@ namespace Ombi.Controllers /// /// [HttpPost("update")] - public bool ForceUpdate() + public async Task ForceUpdate() { - //BackgroundJob.Enqueue(() => _updater.Update(null)); + + await OmbiQuartz.TriggerJob(nameof(IOmbiAutomaticUpdater)); return true; } @@ -97,9 +98,9 @@ namespace Ombi.Controllers /// /// [HttpPost("plexuserimporter")] - public bool PlexUserImporter() + public async Task PlexUserImporter() { - //BackgroundJob.Enqueue(() => _plexUserImporter.Start()); //TODO + await OmbiQuartz.TriggerJob(nameof(IPlexUserImporter)); return true; } @@ -108,9 +109,9 @@ namespace Ombi.Controllers /// /// [HttpPost("embyuserimporter")] - public bool EmbyUserImporter() + public async Task EmbyUserImporter() { - //BackgroundJob.Enqueue(() => _embyUserImporter.Start()); // TODO + await OmbiQuartz.TriggerJob(nameof(IEmbyUserImporter)); return true; } @@ -141,9 +142,9 @@ namespace Ombi.Controllers /// /// [HttpPost("embycontentcacher")] - public bool StartEmbyContentCacher() + public async Task StartEmbyContentCacher() { - //BackgroundJob.Enqueue(() => _embyContentSync.Start()); // TODO + await OmbiQuartz.TriggerJob(nameof(IEmbyContentSync)); return true; } @@ -152,9 +153,9 @@ namespace Ombi.Controllers /// /// [HttpPost("newsletter")] - public bool StartNewsletter() + public async Task StartNewsletter() { - //BackgroundJob.Enqueue(() => _newsletterJob.Start()); // TODO + await OmbiQuartz.TriggerJob(nameof(INewsletterJob)); return true; } } diff --git a/src/Ombi/Controllers/SettingsController.cs b/src/Ombi/Controllers/SettingsController.cs index e77a8fd7a..399375f95 100644 --- a/src/Ombi/Controllers/SettingsController.cs +++ b/src/Ombi/Controllers/SettingsController.cs @@ -27,6 +27,7 @@ using Ombi.Store.Entities; using Ombi.Store.Repository; using Ombi.Api.Github; using Ombi.Core.Engine; +using Ombi.Schedule; namespace Ombi.Controllers { @@ -44,7 +45,6 @@ namespace Ombi.Controllers IMapper mapper, INotificationTemplatesRepository templateRepo, IEmbyApi embyApi, - IRadarrSync radarrSync, ICacheService memCache, IGithubApi githubApi, IRecentlyAddedEngine engine) @@ -53,7 +53,6 @@ namespace Ombi.Controllers Mapper = mapper; TemplateRepository = templateRepo; _embyApi = embyApi; - _radarrSync = radarrSync; _cache = memCache; _githubApi = githubApi; _recentlyAdded = engine; @@ -63,7 +62,6 @@ namespace Ombi.Controllers private IMapper Mapper { get; } private INotificationTemplatesRepository TemplateRepository { get; } private readonly IEmbyApi _embyApi; - private readonly IRadarrSync _radarrSync; private readonly ICacheService _cache; private readonly IGithubApi _githubApi; private readonly IRecentlyAddedEngine _recentlyAdded; @@ -387,7 +385,8 @@ namespace Ombi.Controllers { _cache.Remove(CacheKeys.RadarrRootProfiles); _cache.Remove(CacheKeys.RadarrQualityProfiles); - //BackgroundJob.Enqueue(() => _radarrSync.CacheContent()); // TODO + + await OmbiQuartz.TriggerJob(nameof(IRadarrSync)); } return result; } diff --git a/src/Ombi/Startup.cs b/src/Ombi/Startup.cs index 308e37a69..6f0d4a7ff 100644 --- a/src/Ombi/Startup.cs +++ b/src/Ombi/Startup.cs @@ -123,7 +123,7 @@ namespace Ombi ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto }); - app.UseQuartz(); + app.UseQuartz().GetAwaiter().GetResult(); var ctx = serviceProvider.GetService(); loggerFactory.AddSerilog();