mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-16 02:02:55 -07:00
swap out the scheduler #2750
This commit is contained in:
parent
52d9a7a586
commit
c3c0228b45
14 changed files with 117 additions and 87 deletions
|
@ -32,7 +32,7 @@ namespace Ombi.Schedule.Tests
|
||||||
[Test]
|
[Test]
|
||||||
public async Task DoesNotRun_WhenDisabled()
|
public async Task DoesNotRun_WhenDisabled()
|
||||||
{
|
{
|
||||||
await Job.Start();
|
await Job.Execute(null);
|
||||||
Repo.Verify(x => x.GetAll(),Times.Never);
|
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 });
|
Settings.Setup(x => x.GetSettingsAsync()).ReturnsAsync(new IssueSettings { DeleteIssues = true, DaysAfterResolvedToDelete = 5 });
|
||||||
Repo.Setup(x => x.GetAll()).Returns(new EnumerableQuery<Issues>(issues));
|
Repo.Setup(x => x.GetAll()).Returns(new EnumerableQuery<Issues>(issues));
|
||||||
await Job.Start();
|
await Job.Execute(null);
|
||||||
|
|
||||||
Assert.That(issues.First().Status, Is.EqualTo(IssueStatus.Deleted));
|
Assert.That(issues.First().Status, Is.EqualTo(IssueStatus.Deleted));
|
||||||
Repo.Verify(x => x.SaveChangesAsync(), Times.Once);
|
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 });
|
Settings.Setup(x => x.GetSettingsAsync()).ReturnsAsync(new IssueSettings { DeleteIssues = true, DaysAfterResolvedToDelete = 5 });
|
||||||
Repo.Setup(x => x.GetAll()).Returns(new EnumerableQuery<Issues>(issues));
|
Repo.Setup(x => x.GetAll()).Returns(new EnumerableQuery<Issues>(issues));
|
||||||
await Job.Start();
|
await Job.Execute(null);
|
||||||
|
|
||||||
Assert.That(issues[0].Status, Is.Not.EqualTo(IssueStatus.Deleted));
|
Assert.That(issues[0].Status, Is.Not.EqualTo(IssueStatus.Deleted));
|
||||||
Assert.That(issues[1].Status, Is.EqualTo(IssueStatus.Deleted));
|
Assert.That(issues[1].Status, Is.EqualTo(IssueStatus.Deleted));
|
||||||
|
|
36
src/Ombi.Schedule.Tests/OmbiQuartzTests.cs
Normal file
36
src/Ombi.Schedule.Tests/OmbiQuartzTests.cs
Normal file
|
@ -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<IScheduler>();
|
||||||
|
scheduleMock.Setup(x => x.TriggerJob(It.IsAny<JobKey>(),
|
||||||
|
It.IsAny<CancellationToken>()));
|
||||||
|
var sut = new QuartzMock(scheduleMock);
|
||||||
|
|
||||||
|
await QuartzMock.TriggerJob("ABC");
|
||||||
|
|
||||||
|
scheduleMock.Verify(x => x.TriggerJob(It.Is<JobKey>(j => j.Name == "ABC"),
|
||||||
|
default(CancellationToken)), Times.Once);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public class QuartzMock : OmbiQuartz
|
||||||
|
{
|
||||||
|
public QuartzMock(Mock<IScheduler> mock)
|
||||||
|
{
|
||||||
|
_instance = this;
|
||||||
|
_scheduler = mock.Object;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -46,7 +46,7 @@ namespace Ombi.Schedule.Tests
|
||||||
_movie.Setup(x => x.GetAll()).Returns(new List<MovieRequests> { request }.AsQueryable());
|
_movie.Setup(x => x.GetAll()).Returns(new List<MovieRequests> { request }.AsQueryable());
|
||||||
_repo.Setup(x => x.Get("test")).ReturnsAsync(new PlexServerContent());
|
_repo.Setup(x => x.Get("test")).ReturnsAsync(new PlexServerContent());
|
||||||
|
|
||||||
await Checker.Start();
|
await Checker.Execute(null);
|
||||||
|
|
||||||
_movie.Verify(x => x.Save(), Times.Once);
|
_movie.Verify(x => x.Save(), Times.Once);
|
||||||
|
|
||||||
|
@ -62,8 +62,8 @@ namespace Ombi.Schedule.Tests
|
||||||
};
|
};
|
||||||
_movie.Setup(x => x.GetAll()).Returns(new List<MovieRequests> { request }.AsQueryable());
|
_movie.Setup(x => x.GetAll()).Returns(new List<MovieRequests> { request }.AsQueryable());
|
||||||
|
|
||||||
await Checker.Start();
|
await Checker.Execute(null);
|
||||||
|
|
||||||
Assert.False(request.Available);
|
Assert.False(request.Available);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@ namespace Ombi.Schedule.Tests
|
||||||
}.AsQueryable);
|
}.AsQueryable);
|
||||||
_repo.Setup(x => x.Include(It.IsAny<IQueryable<PlexEpisode>>(),It.IsAny<Expression<Func<PlexEpisode, PlexServerContent>>>()));
|
_repo.Setup(x => x.Include(It.IsAny<IQueryable<PlexEpisode>>(),It.IsAny<Expression<Func<PlexEpisode, PlexServerContent>>>()));
|
||||||
|
|
||||||
await Checker.Start();
|
await Checker.Execute(null);
|
||||||
|
|
||||||
_tv.Verify(x => x.Save(), Times.Once);
|
_tv.Verify(x => x.Save(), Times.Once);
|
||||||
|
|
||||||
|
|
|
@ -21,22 +21,18 @@ namespace Ombi.Schedule.Jobs.Emby
|
||||||
public class EmbyContentSync : IEmbyContentSync
|
public class EmbyContentSync : IEmbyContentSync
|
||||||
{
|
{
|
||||||
public EmbyContentSync(ISettingsService<EmbySettings> settings, IEmbyApi api, ILogger<EmbyContentSync> logger,
|
public EmbyContentSync(ISettingsService<EmbySettings> settings, IEmbyApi api, ILogger<EmbyContentSync> logger,
|
||||||
IEmbyContentRepository repo, IEmbyEpisodeSync epSync, IRefreshMetadata metadata)
|
IEmbyContentRepository repo)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_settings = settings;
|
_settings = settings;
|
||||||
_api = api;
|
_api = api;
|
||||||
_repo = repo;
|
_repo = repo;
|
||||||
_episodeSync = epSync;
|
|
||||||
_metadata = metadata;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly ILogger<EmbyContentSync> _logger;
|
private readonly ILogger<EmbyContentSync> _logger;
|
||||||
private readonly ISettingsService<EmbySettings> _settings;
|
private readonly ISettingsService<EmbySettings> _settings;
|
||||||
private readonly IEmbyApi _api;
|
private readonly IEmbyApi _api;
|
||||||
private readonly IEmbyContentRepository _repo;
|
private readonly IEmbyContentRepository _repo;
|
||||||
private readonly IEmbyEpisodeSync _episodeSync;
|
|
||||||
private readonly IRefreshMetadata _metadata;
|
|
||||||
|
|
||||||
|
|
||||||
public async Task Execute(IJobExecutionContext job)
|
public async Task Execute(IJobExecutionContext job)
|
||||||
|
@ -58,6 +54,10 @@ namespace Ombi.Schedule.Jobs.Emby
|
||||||
}
|
}
|
||||||
|
|
||||||
// Episodes
|
// Episodes
|
||||||
|
|
||||||
|
await OmbiQuartz.TriggerJob(nameof(IEmbyEpisodeSync));
|
||||||
|
|
||||||
|
await OmbiQuartz.TriggerJob(nameof(IRefreshMetadata));
|
||||||
//BackgroundJob.Enqueue(() => _episodeSync.Start());
|
//BackgroundJob.Enqueue(() => _episodeSync.Start());
|
||||||
//BackgroundJob.Enqueue(() => _metadata.Start());
|
//BackgroundJob.Enqueue(() => _metadata.Start());
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,21 +42,18 @@ namespace Ombi.Schedule.Jobs.Emby
|
||||||
{
|
{
|
||||||
public class EmbyEpisodeSync : IEmbyEpisodeSync
|
public class EmbyEpisodeSync : IEmbyEpisodeSync
|
||||||
{
|
{
|
||||||
public EmbyEpisodeSync(ISettingsService<EmbySettings> s, IEmbyApi api, ILogger<EmbyEpisodeSync> l, IEmbyContentRepository repo,
|
public EmbyEpisodeSync(ISettingsService<EmbySettings> s, IEmbyApi api, ILogger<EmbyEpisodeSync> l, IEmbyContentRepository repo)
|
||||||
IEmbyAvaliabilityChecker checker)
|
|
||||||
{
|
{
|
||||||
_api = api;
|
_api = api;
|
||||||
_logger = l;
|
_logger = l;
|
||||||
_settings = s;
|
_settings = s;
|
||||||
_repo = repo;
|
_repo = repo;
|
||||||
_avaliabilityChecker = checker;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly ISettingsService<EmbySettings> _settings;
|
private readonly ISettingsService<EmbySettings> _settings;
|
||||||
private readonly IEmbyApi _api;
|
private readonly IEmbyApi _api;
|
||||||
private readonly ILogger<EmbyEpisodeSync> _logger;
|
private readonly ILogger<EmbyEpisodeSync> _logger;
|
||||||
private readonly IEmbyContentRepository _repo;
|
private readonly IEmbyContentRepository _repo;
|
||||||
private readonly IEmbyAvaliabilityChecker _avaliabilityChecker;
|
|
||||||
|
|
||||||
|
|
||||||
public async Task Execute(IJobExecutionContext job)
|
public async Task Execute(IJobExecutionContext job)
|
||||||
|
@ -68,7 +65,8 @@ namespace Ombi.Schedule.Jobs.Emby
|
||||||
await CacheEpisodes(server);
|
await CacheEpisodes(server);
|
||||||
}
|
}
|
||||||
|
|
||||||
//BackgroundJob.Enqueue(() => _avaliabilityChecker.Start());
|
|
||||||
|
await OmbiQuartz.TriggerJob(nameof(IEmbyAvaliabilityChecker));
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task CacheEpisodes(EmbyServers server)
|
private async Task CacheEpisodes(EmbyServers server)
|
||||||
|
@ -143,7 +141,6 @@ namespace Ombi.Schedule.Jobs.Emby
|
||||||
{
|
{
|
||||||
_settings?.Dispose();
|
_settings?.Dispose();
|
||||||
_repo?.Dispose();
|
_repo?.Dispose();
|
||||||
_avaliabilityChecker?.Dispose();
|
|
||||||
}
|
}
|
||||||
_disposed = true;
|
_disposed = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,13 +16,12 @@ namespace Ombi.Schedule.Jobs.Ombi
|
||||||
public class MediaDatabaseRefresh : IMediaDatabaseRefresh
|
public class MediaDatabaseRefresh : IMediaDatabaseRefresh
|
||||||
{
|
{
|
||||||
public MediaDatabaseRefresh(ISettingsService<PlexSettings> s, ILogger<MediaDatabaseRefresh> log,
|
public MediaDatabaseRefresh(ISettingsService<PlexSettings> s, ILogger<MediaDatabaseRefresh> log,
|
||||||
IPlexContentRepository plexRepo, IEmbyContentRepository embyRepo, IEmbyContentSync embySync)
|
IPlexContentRepository plexRepo, IEmbyContentRepository embyRepo)
|
||||||
{
|
{
|
||||||
_settings = s;
|
_settings = s;
|
||||||
_log = log;
|
_log = log;
|
||||||
_plexRepo = plexRepo;
|
_plexRepo = plexRepo;
|
||||||
_embyRepo = embyRepo;
|
_embyRepo = embyRepo;
|
||||||
_embyContentSync = embySync;
|
|
||||||
_settings.ClearCache();
|
_settings.ClearCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +29,6 @@ namespace Ombi.Schedule.Jobs.Ombi
|
||||||
private readonly ILogger _log;
|
private readonly ILogger _log;
|
||||||
private readonly IPlexContentRepository _plexRepo;
|
private readonly IPlexContentRepository _plexRepo;
|
||||||
private readonly IEmbyContentRepository _embyRepo;
|
private readonly IEmbyContentRepository _embyRepo;
|
||||||
private readonly IEmbyContentSync _embyContentSync;
|
|
||||||
|
|
||||||
public async Task Execute(IJobExecutionContext job)
|
public async Task Execute(IJobExecutionContext job)
|
||||||
{
|
{
|
||||||
|
@ -61,7 +59,7 @@ namespace Ombi.Schedule.Jobs.Ombi
|
||||||
await _embyRepo.ExecuteSql(episodeSQL);
|
await _embyRepo.ExecuteSql(episodeSQL);
|
||||||
await _embyRepo.ExecuteSql(mainSql);
|
await _embyRepo.ExecuteSql(mainSql);
|
||||||
|
|
||||||
//BackgroundJob.Enqueue(() => _embyContentSync.Start()); // TODO
|
await OmbiQuartz.TriggerJob(nameof(IEmbyContentSync));
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -23,8 +23,7 @@ namespace Ombi.Schedule.Jobs.Ombi
|
||||||
{
|
{
|
||||||
public RefreshMetadata(IPlexContentRepository plexRepo, IEmbyContentRepository embyRepo,
|
public RefreshMetadata(IPlexContentRepository plexRepo, IEmbyContentRepository embyRepo,
|
||||||
ILogger<RefreshMetadata> log, ITvMazeApi tvApi, ISettingsService<PlexSettings> plexSettings,
|
ILogger<RefreshMetadata> log, ITvMazeApi tvApi, ISettingsService<PlexSettings> plexSettings,
|
||||||
IMovieDbApi movieApi, ISettingsService<EmbySettings> embySettings, IPlexAvailabilityChecker plexAvailability, IEmbyAvaliabilityChecker embyAvaliability,
|
IMovieDbApi movieApi, ISettingsService<EmbySettings> embySettings, IEmbyApi embyApi)
|
||||||
IEmbyApi embyApi)
|
|
||||||
{
|
{
|
||||||
_plexRepo = plexRepo;
|
_plexRepo = plexRepo;
|
||||||
_embyRepo = embyRepo;
|
_embyRepo = embyRepo;
|
||||||
|
@ -33,15 +32,11 @@ namespace Ombi.Schedule.Jobs.Ombi
|
||||||
_tvApi = tvApi;
|
_tvApi = tvApi;
|
||||||
_plexSettings = plexSettings;
|
_plexSettings = plexSettings;
|
||||||
_embySettings = embySettings;
|
_embySettings = embySettings;
|
||||||
_plexAvailabilityChecker = plexAvailability;
|
|
||||||
_embyAvaliabilityChecker = embyAvaliability;
|
|
||||||
_embyApi = embyApi;
|
_embyApi = embyApi;
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly IPlexContentRepository _plexRepo;
|
private readonly IPlexContentRepository _plexRepo;
|
||||||
private readonly IEmbyContentRepository _embyRepo;
|
private readonly IEmbyContentRepository _embyRepo;
|
||||||
private readonly IPlexAvailabilityChecker _plexAvailabilityChecker;
|
|
||||||
private readonly IEmbyAvaliabilityChecker _embyAvaliabilityChecker;
|
|
||||||
private readonly ILogger _log;
|
private readonly ILogger _log;
|
||||||
private readonly IMovieDbApi _movieApi;
|
private readonly IMovieDbApi _movieApi;
|
||||||
private readonly ITvMazeApi _tvApi;
|
private readonly ITvMazeApi _tvApi;
|
||||||
|
@ -94,12 +89,12 @@ namespace Ombi.Schedule.Jobs.Ombi
|
||||||
{
|
{
|
||||||
if (plexSettings.Enable)
|
if (plexSettings.Enable)
|
||||||
{
|
{
|
||||||
//BackgroundJob.Enqueue(() => _plexAvailabilityChecker.Start()); // TODO
|
await OmbiQuartz.TriggerJob(nameof(IPlexAvailabilityChecker));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (embySettings.Enable)
|
if (embySettings.Enable)
|
||||||
{
|
{
|
||||||
//BackgroundJob.Enqueue(() => _embyAvaliabilityChecker.Start()); // TODO
|
await OmbiQuartz.TriggerJob(nameof(IEmbyAvaliabilityChecker));
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ namespace Ombi.Schedule.Jobs.Plex
|
||||||
public class PlexContentSync : IPlexContentSync
|
public class PlexContentSync : IPlexContentSync
|
||||||
{
|
{
|
||||||
public PlexContentSync(ISettingsService<PlexSettings> plex, IPlexApi plexApi, ILogger<PlexContentSync> logger, IPlexContentRepository repo,
|
public PlexContentSync(ISettingsService<PlexSettings> plex, IPlexApi plexApi, ILogger<PlexContentSync> logger, IPlexContentRepository repo,
|
||||||
IPlexEpisodeSync epsiodeSync, IRefreshMetadata metadataRefresh, IPlexAvailabilityChecker checker)
|
IPlexEpisodeSync epsiodeSync, IRefreshMetadata metadataRefresh)
|
||||||
{
|
{
|
||||||
Plex = plex;
|
Plex = plex;
|
||||||
PlexApi = plexApi;
|
PlexApi = plexApi;
|
||||||
|
@ -57,7 +57,6 @@ namespace Ombi.Schedule.Jobs.Plex
|
||||||
Repo = repo;
|
Repo = repo;
|
||||||
EpisodeSync = epsiodeSync;
|
EpisodeSync = epsiodeSync;
|
||||||
Metadata = metadataRefresh;
|
Metadata = metadataRefresh;
|
||||||
Checker = checker;
|
|
||||||
Plex.ClearCache();
|
Plex.ClearCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +66,6 @@ namespace Ombi.Schedule.Jobs.Plex
|
||||||
private IPlexContentRepository Repo { get; }
|
private IPlexContentRepository Repo { get; }
|
||||||
private IPlexEpisodeSync EpisodeSync { get; }
|
private IPlexEpisodeSync EpisodeSync { get; }
|
||||||
private IRefreshMetadata Metadata { get; }
|
private IRefreshMetadata Metadata { get; }
|
||||||
private IPlexAvailabilityChecker Checker { get; }
|
|
||||||
|
|
||||||
public async Task Execute(IJobExecutionContext context)
|
public async Task Execute(IJobExecutionContext context)
|
||||||
{
|
{
|
||||||
|
@ -105,7 +103,8 @@ namespace Ombi.Schedule.Jobs.Plex
|
||||||
if (!recentlyAddedSearch)
|
if (!recentlyAddedSearch)
|
||||||
{
|
{
|
||||||
Logger.LogInformation("Starting EP Cacher");
|
Logger.LogInformation("Starting EP Cacher");
|
||||||
//BackgroundJob.Enqueue(() => EpisodeSync.Start()); //TODO
|
|
||||||
|
await OmbiQuartz.TriggerJob(nameof(IPlexEpisodeSync));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((processedContent?.HasProcessedContent ?? false) && recentlyAddedSearch)
|
if ((processedContent?.HasProcessedContent ?? false) && recentlyAddedSearch)
|
||||||
|
@ -116,7 +115,8 @@ namespace Ombi.Schedule.Jobs.Plex
|
||||||
|
|
||||||
if ((processedContent?.HasProcessedEpisodes ?? false) && recentlyAddedSearch)
|
if ((processedContent?.HasProcessedEpisodes ?? false) && recentlyAddedSearch)
|
||||||
{
|
{
|
||||||
//BackgroundJob.Enqueue(() => Checker.Start()); // TODO
|
|
||||||
|
await OmbiQuartz.TriggerJob(nameof(IPlexAvailabilityChecker));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,13 +20,12 @@ namespace Ombi.Schedule.Jobs.Plex
|
||||||
public class PlexEpisodeSync : IPlexEpisodeSync
|
public class PlexEpisodeSync : IPlexEpisodeSync
|
||||||
{
|
{
|
||||||
public PlexEpisodeSync(ISettingsService<PlexSettings> s, ILogger<PlexEpisodeSync> log, IPlexApi plexApi,
|
public PlexEpisodeSync(ISettingsService<PlexSettings> s, ILogger<PlexEpisodeSync> log, IPlexApi plexApi,
|
||||||
IPlexContentRepository repo, IPlexAvailabilityChecker a)
|
IPlexContentRepository repo)
|
||||||
{
|
{
|
||||||
_settings = s;
|
_settings = s;
|
||||||
_log = log;
|
_log = log;
|
||||||
_api = plexApi;
|
_api = plexApi;
|
||||||
_repo = repo;
|
_repo = repo;
|
||||||
_availabilityChecker = a;
|
|
||||||
_settings.ClearCache();
|
_settings.ClearCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +33,6 @@ namespace Ombi.Schedule.Jobs.Plex
|
||||||
private readonly ILogger<PlexEpisodeSync> _log;
|
private readonly ILogger<PlexEpisodeSync> _log;
|
||||||
private readonly IPlexApi _api;
|
private readonly IPlexApi _api;
|
||||||
private readonly IPlexContentRepository _repo;
|
private readonly IPlexContentRepository _repo;
|
||||||
private readonly IPlexAvailabilityChecker _availabilityChecker;
|
|
||||||
|
|
||||||
public async Task Execute(IJobExecutionContext job)
|
public async Task Execute(IJobExecutionContext job)
|
||||||
{
|
{
|
||||||
|
@ -57,6 +55,8 @@ namespace Ombi.Schedule.Jobs.Plex
|
||||||
_log.LogError(LoggingEvents.Cacher, e, "Caching Episodes Failed");
|
_log.LogError(LoggingEvents.Cacher, e, "Caching Episodes Failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
await OmbiQuartz.TriggerJob(nameof(IPlexAvailabilityChecker));
|
||||||
//BackgroundJob.Enqueue(() => _availabilityChecker.Start()); // TODO
|
//BackgroundJob.Enqueue(() => _availabilityChecker.Start()); // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Quartz;
|
using Quartz;
|
||||||
using Quartz.Impl;
|
using Quartz.Impl;
|
||||||
using Quartz.Spi;
|
using Quartz.Spi;
|
||||||
|
@ -7,19 +8,19 @@ namespace Ombi.Schedule
|
||||||
{
|
{
|
||||||
public class OmbiQuartz
|
public class OmbiQuartz
|
||||||
{
|
{
|
||||||
private IScheduler _scheduler;
|
protected IScheduler _scheduler { get; set; }
|
||||||
|
|
||||||
public static IScheduler Scheduler => Instance._scheduler;
|
public static IScheduler Scheduler => Instance._scheduler;
|
||||||
|
|
||||||
// Singleton
|
// Singleton
|
||||||
private static OmbiQuartz _instance;
|
protected static OmbiQuartz _instance;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Singleton
|
/// Singleton
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static OmbiQuartz Instance => _instance ?? (_instance = new OmbiQuartz());
|
public static OmbiQuartz Instance => _instance ?? (_instance = new OmbiQuartz());
|
||||||
|
|
||||||
private OmbiQuartz()
|
protected OmbiQuartz()
|
||||||
{
|
{
|
||||||
Init();
|
Init();
|
||||||
}
|
}
|
||||||
|
@ -35,7 +36,7 @@ namespace Ombi.Schedule
|
||||||
return Scheduler;
|
return Scheduler;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async void AddJob<T>(string name, string group, string cronExpression, Dictionary<string, string> jobData = null)
|
public async Task AddJob<T>(string name, string group, string cronExpression, Dictionary<string, string> jobData = null)
|
||||||
where T : IJob
|
where T : IJob
|
||||||
{
|
{
|
||||||
var jobBuilder = JobBuilder.Create<T>()
|
var jobBuilder = JobBuilder.Create<T>()
|
||||||
|
@ -52,16 +53,18 @@ namespace Ombi.Schedule
|
||||||
|
|
||||||
ITrigger jobTrigger = TriggerBuilder.Create()
|
ITrigger jobTrigger = TriggerBuilder.Create()
|
||||||
.WithIdentity(name + "Trigger", group)
|
.WithIdentity(name + "Trigger", group)
|
||||||
|
|
||||||
.StartNow()
|
|
||||||
|
|
||||||
.WithCronSchedule(cronExpression)
|
.WithCronSchedule(cronExpression)
|
||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
await Scheduler.ScheduleJob(job, jobTrigger);
|
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();
|
await Scheduler.Start();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Builder;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using Ombi.Core.Settings;
|
using Ombi.Core.Settings;
|
||||||
using Ombi.Schedule.Jobs;
|
using Ombi.Schedule.Jobs;
|
||||||
|
@ -38,7 +39,7 @@ namespace Ombi.Schedule
|
||||||
// .Build();
|
// .Build();
|
||||||
//}
|
//}
|
||||||
|
|
||||||
public static void UseQuartz(this IApplicationBuilder app)
|
public static async Task UseQuartz(this IApplicationBuilder app)
|
||||||
{
|
{
|
||||||
// Job Factory through IOC container
|
// Job Factory through IOC container
|
||||||
var jobFactory = (IJobFactory)app.ApplicationServices.GetService(typeof(IJobFactory));
|
var jobFactory = (IJobFactory)app.ApplicationServices.GetService(typeof(IJobFactory));
|
||||||
|
@ -48,47 +49,47 @@ namespace Ombi.Schedule
|
||||||
OmbiQuartz.Instance.UseJobFactory(jobFactory);
|
OmbiQuartz.Instance.UseJobFactory(jobFactory);
|
||||||
|
|
||||||
// Run Quartz
|
// Run Quartz
|
||||||
OmbiQuartz.Start();
|
await OmbiQuartz.Start();
|
||||||
|
|
||||||
// Run configuration
|
// Run configuration
|
||||||
AddPlex(s);
|
await AddPlex(s);
|
||||||
AddEmby(s);
|
await AddEmby(s);
|
||||||
AddDvrApps(s);
|
await AddDvrApps(s);
|
||||||
AddSystem(s);
|
await AddSystem(s);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void AddSystem(JobSettings s)
|
private static async Task AddSystem(JobSettings s)
|
||||||
{
|
{
|
||||||
OmbiQuartz.Instance.AddJob<IRefreshMetadata>(nameof(IRefreshMetadata), "System", JobSettingsHelper.RefreshMetadata(s));
|
await OmbiQuartz.Instance.AddJob<IRefreshMetadata>(nameof(IRefreshMetadata), "System", JobSettingsHelper.RefreshMetadata(s));
|
||||||
OmbiQuartz.Instance.AddJob<IIssuesPurge>(nameof(IIssuesPurge), "System", JobSettingsHelper.IssuePurge(s));
|
await OmbiQuartz.Instance.AddJob<IIssuesPurge>(nameof(IIssuesPurge), "System", JobSettingsHelper.IssuePurge(s));
|
||||||
//OmbiQuartz.Instance.AddJob<IOmbiAutomaticUpdater>(nameof(IOmbiAutomaticUpdater), "System", JobSettingsHelper.Updater(s));
|
//OmbiQuartz.Instance.AddJob<IOmbiAutomaticUpdater>(nameof(IOmbiAutomaticUpdater), "System", JobSettingsHelper.Updater(s));
|
||||||
OmbiQuartz.Instance.AddJob<INewsletterJob>(nameof(INewsletterJob), "System", JobSettingsHelper.Newsletter(s));
|
await OmbiQuartz.Instance.AddJob<INewsletterJob>(nameof(INewsletterJob), "System", JobSettingsHelper.Newsletter(s));
|
||||||
OmbiQuartz.Instance.AddJob<IResendFailedRequests>(nameof(IResendFailedRequests), "System", JobSettingsHelper.ResendFailedRequests(s));
|
await OmbiQuartz.Instance.AddJob<IResendFailedRequests>(nameof(IResendFailedRequests), "System", JobSettingsHelper.ResendFailedRequests(s));
|
||||||
OmbiQuartz.Instance.AddJob<IMediaDatabaseRefresh>(nameof(IMediaDatabaseRefresh), "System", JobSettingsHelper.MediaDatabaseRefresh(s));
|
await OmbiQuartz.Instance.AddJob<IMediaDatabaseRefresh>(nameof(IMediaDatabaseRefresh), "System", JobSettingsHelper.MediaDatabaseRefresh(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void AddDvrApps(JobSettings s)
|
private static async Task AddDvrApps(JobSettings s)
|
||||||
{
|
{
|
||||||
OmbiQuartz.Instance.AddJob<ISonarrSync>(nameof(ISonarrSync), "DVR", JobSettingsHelper.Sonarr(s));
|
await OmbiQuartz.Instance.AddJob<ISonarrSync>(nameof(ISonarrSync), "DVR", JobSettingsHelper.Sonarr(s));
|
||||||
OmbiQuartz.Instance.AddJob<IRadarrSync>(nameof(IRadarrSync), "DVR", JobSettingsHelper.Radarr(s));
|
await OmbiQuartz.Instance.AddJob<IRadarrSync>(nameof(IRadarrSync), "DVR", JobSettingsHelper.Radarr(s));
|
||||||
OmbiQuartz.Instance.AddJob<ICouchPotatoSync>(nameof(ICouchPotatoSync), "DVR", JobSettingsHelper.CouchPotato(s));
|
await OmbiQuartz.Instance.AddJob<ICouchPotatoSync>(nameof(ICouchPotatoSync), "DVR", JobSettingsHelper.CouchPotato(s));
|
||||||
OmbiQuartz.Instance.AddJob<ISickRageSync>(nameof(ISickRageSync), "DVR", JobSettingsHelper.SickRageSync(s));
|
await OmbiQuartz.Instance.AddJob<ISickRageSync>(nameof(ISickRageSync), "DVR", JobSettingsHelper.SickRageSync(s));
|
||||||
OmbiQuartz.Instance.AddJob<ILidarrArtistSync>(nameof(ILidarrArtistSync), "DVR", JobSettingsHelper.LidarrArtistSync(s));
|
await OmbiQuartz.Instance.AddJob<ILidarrArtistSync>(nameof(ILidarrArtistSync), "DVR", JobSettingsHelper.LidarrArtistSync(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void AddPlex(JobSettings s)
|
private static async Task AddPlex(JobSettings s)
|
||||||
{
|
{
|
||||||
OmbiQuartz.Instance.AddJob<IPlexContentSync>(nameof(IPlexContentSync), "Plex", JobSettingsHelper.PlexContent(s), new Dictionary<string, string> { { "recentlyAddedSearch", "false" } });
|
await OmbiQuartz.Instance.AddJob<IPlexContentSync>(nameof(IPlexContentSync), "Plex", JobSettingsHelper.PlexContent(s), new Dictionary<string, string> { { "recentlyAddedSearch", "false" } });
|
||||||
OmbiQuartz.Instance.AddJob<IPlexContentSync>(nameof(IPlexContentSync) + "RecentlyAdded", "Plex", JobSettingsHelper.PlexContent(s), new Dictionary<string, string> { { "recentlyAddedSearch", "true" } });
|
await OmbiQuartz.Instance.AddJob<IPlexContentSync>(nameof(IPlexContentSync) + "RecentlyAdded", "Plex", JobSettingsHelper.PlexContent(s), new Dictionary<string, string> { { "recentlyAddedSearch", "true" } });
|
||||||
OmbiQuartz.Instance.AddJob<IPlexRecentlyAddedSync>(nameof(IPlexRecentlyAddedSync), "Plex", JobSettingsHelper.PlexRecentlyAdded(s));
|
await OmbiQuartz.Instance.AddJob<IPlexRecentlyAddedSync>(nameof(IPlexRecentlyAddedSync), "Plex", JobSettingsHelper.PlexRecentlyAdded(s));
|
||||||
OmbiQuartz.Instance.AddJob<IPlexUserImporter>(nameof(IPlexUserImporter), "Plex", JobSettingsHelper.UserImporter(s));
|
await OmbiQuartz.Instance.AddJob<IPlexUserImporter>(nameof(IPlexUserImporter), "Plex", JobSettingsHelper.UserImporter(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void AddEmby(JobSettings s)
|
private static async Task AddEmby(JobSettings s)
|
||||||
{
|
{
|
||||||
OmbiQuartz.Instance.AddJob<IEmbyContentSync>(nameof(IEmbyContentSync), "Emby", JobSettingsHelper.EmbyContent(s));
|
await OmbiQuartz.Instance.AddJob<IEmbyContentSync>(nameof(IEmbyContentSync), "Emby", JobSettingsHelper.EmbyContent(s));
|
||||||
OmbiQuartz.Instance.AddJob<IEmbyUserImporter>(nameof(IEmbyUserImporter), "Emby", JobSettingsHelper.UserImporter(s));
|
await OmbiQuartz.Instance.AddJob<IEmbyUserImporter>(nameof(IEmbyUserImporter), "Emby", JobSettingsHelper.UserImporter(s));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -48,9 +48,10 @@ namespace Ombi.Controllers
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost("update")]
|
[HttpPost("update")]
|
||||||
public bool ForceUpdate()
|
public async Task<bool> ForceUpdate()
|
||||||
{
|
{
|
||||||
//BackgroundJob.Enqueue(() => _updater.Update(null));
|
|
||||||
|
await OmbiQuartz.TriggerJob(nameof(IOmbiAutomaticUpdater));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,9 +98,9 @@ namespace Ombi.Controllers
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost("plexuserimporter")]
|
[HttpPost("plexuserimporter")]
|
||||||
public bool PlexUserImporter()
|
public async Task<bool> PlexUserImporter()
|
||||||
{
|
{
|
||||||
//BackgroundJob.Enqueue(() => _plexUserImporter.Start()); //TODO
|
await OmbiQuartz.TriggerJob(nameof(IPlexUserImporter));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -108,9 +109,9 @@ namespace Ombi.Controllers
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost("embyuserimporter")]
|
[HttpPost("embyuserimporter")]
|
||||||
public bool EmbyUserImporter()
|
public async Task<bool> EmbyUserImporter()
|
||||||
{
|
{
|
||||||
//BackgroundJob.Enqueue(() => _embyUserImporter.Start()); // TODO
|
await OmbiQuartz.TriggerJob(nameof(IEmbyUserImporter));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,9 +142,9 @@ namespace Ombi.Controllers
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost("embycontentcacher")]
|
[HttpPost("embycontentcacher")]
|
||||||
public bool StartEmbyContentCacher()
|
public async Task<bool> StartEmbyContentCacher()
|
||||||
{
|
{
|
||||||
//BackgroundJob.Enqueue(() => _embyContentSync.Start()); // TODO
|
await OmbiQuartz.TriggerJob(nameof(IEmbyContentSync));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,9 +153,9 @@ namespace Ombi.Controllers
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
[HttpPost("newsletter")]
|
[HttpPost("newsletter")]
|
||||||
public bool StartNewsletter()
|
public async Task<bool> StartNewsletter()
|
||||||
{
|
{
|
||||||
//BackgroundJob.Enqueue(() => _newsletterJob.Start()); // TODO
|
await OmbiQuartz.TriggerJob(nameof(INewsletterJob));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ using Ombi.Store.Entities;
|
||||||
using Ombi.Store.Repository;
|
using Ombi.Store.Repository;
|
||||||
using Ombi.Api.Github;
|
using Ombi.Api.Github;
|
||||||
using Ombi.Core.Engine;
|
using Ombi.Core.Engine;
|
||||||
|
using Ombi.Schedule;
|
||||||
|
|
||||||
namespace Ombi.Controllers
|
namespace Ombi.Controllers
|
||||||
{
|
{
|
||||||
|
@ -44,7 +45,6 @@ namespace Ombi.Controllers
|
||||||
IMapper mapper,
|
IMapper mapper,
|
||||||
INotificationTemplatesRepository templateRepo,
|
INotificationTemplatesRepository templateRepo,
|
||||||
IEmbyApi embyApi,
|
IEmbyApi embyApi,
|
||||||
IRadarrSync radarrSync,
|
|
||||||
ICacheService memCache,
|
ICacheService memCache,
|
||||||
IGithubApi githubApi,
|
IGithubApi githubApi,
|
||||||
IRecentlyAddedEngine engine)
|
IRecentlyAddedEngine engine)
|
||||||
|
@ -53,7 +53,6 @@ namespace Ombi.Controllers
|
||||||
Mapper = mapper;
|
Mapper = mapper;
|
||||||
TemplateRepository = templateRepo;
|
TemplateRepository = templateRepo;
|
||||||
_embyApi = embyApi;
|
_embyApi = embyApi;
|
||||||
_radarrSync = radarrSync;
|
|
||||||
_cache = memCache;
|
_cache = memCache;
|
||||||
_githubApi = githubApi;
|
_githubApi = githubApi;
|
||||||
_recentlyAdded = engine;
|
_recentlyAdded = engine;
|
||||||
|
@ -63,7 +62,6 @@ namespace Ombi.Controllers
|
||||||
private IMapper Mapper { get; }
|
private IMapper Mapper { get; }
|
||||||
private INotificationTemplatesRepository TemplateRepository { get; }
|
private INotificationTemplatesRepository TemplateRepository { get; }
|
||||||
private readonly IEmbyApi _embyApi;
|
private readonly IEmbyApi _embyApi;
|
||||||
private readonly IRadarrSync _radarrSync;
|
|
||||||
private readonly ICacheService _cache;
|
private readonly ICacheService _cache;
|
||||||
private readonly IGithubApi _githubApi;
|
private readonly IGithubApi _githubApi;
|
||||||
private readonly IRecentlyAddedEngine _recentlyAdded;
|
private readonly IRecentlyAddedEngine _recentlyAdded;
|
||||||
|
@ -387,7 +385,8 @@ namespace Ombi.Controllers
|
||||||
{
|
{
|
||||||
_cache.Remove(CacheKeys.RadarrRootProfiles);
|
_cache.Remove(CacheKeys.RadarrRootProfiles);
|
||||||
_cache.Remove(CacheKeys.RadarrQualityProfiles);
|
_cache.Remove(CacheKeys.RadarrQualityProfiles);
|
||||||
//BackgroundJob.Enqueue(() => _radarrSync.CacheContent()); // TODO
|
|
||||||
|
await OmbiQuartz.TriggerJob(nameof(IRadarrSync));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,7 +123,7 @@ namespace Ombi
|
||||||
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
|
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
|
||||||
});
|
});
|
||||||
|
|
||||||
app.UseQuartz();
|
app.UseQuartz().GetAwaiter().GetResult();
|
||||||
|
|
||||||
var ctx = serviceProvider.GetService<IOmbiContext>();
|
var ctx = serviceProvider.GetService<IOmbiContext>();
|
||||||
loggerFactory.AddSerilog();
|
loggerFactory.AddSerilog();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue