Merge pull request #2922 from tidusjar/feature/quartz-poc

Feature/quartz poc
pull/2947/head
Jamie 6 years ago committed by GitHub
commit 3f06b2da32
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -61,6 +61,7 @@ using Ombi.Schedule.Jobs.Plex.Interfaces;
using Ombi.Schedule.Jobs.SickRage;
using Ombi.Schedule.Processor;
using Ombi.Store.Entities;
using Quartz.Spi;
namespace Ombi.DependencyInjection
{
@ -180,6 +181,7 @@ namespace Ombi.DependencyInjection
public static void RegisterJobs(this IServiceCollection services)
{
services.AddTransient<IJobFactory, IoCJobFactory>(provider => new IoCJobFactory(provider));
services.AddTransient<IBackgroundJobClient, BackgroundJobClient>();
services.AddTransient<IPlexContentSync, PlexContentSync>();
@ -200,7 +202,7 @@ namespace Ombi.DependencyInjection
services.AddTransient<ISickRageSync, SickRageSync>();
services.AddTransient<IRefreshMetadata, RefreshMetadata>();
services.AddTransient<INewsletterJob, NewsletterJob>();
services.AddTransient<IPlexRecentlyAddedSync, PlexRecentlyAddedSync>();
//services.AddTransient<IPlexRecentlyAddedSync, PlexRecentlyAddedSync>();
services.AddTransient<ILidarrAlbumSync, LidarrAlbumSync>();
services.AddTransient<ILidarrArtistSync, LidarrArtistSync>();
services.AddTransient<ILidarrAvailabilityChecker, LidarrAvailabilityChecker>();

@ -16,7 +16,6 @@
// You should have received a copy of the GNU Lesser General Public
// License along with Hangfire. If not, see <http://www.gnu.org/licenses/>.
using System;
/// <summary>
/// Helper class that provides common values for the cron expressions.
/// </summary>
@ -44,7 +43,7 @@
/// <param name="minute">The minute in which the schedule will be activated (0-59).</param>
public static string Hourly(int minute)
{
return $"{minute} * * * *";
return $"0 {minute} 0/1 1/1 * ? *";
}
/// <summary>
@ -73,7 +72,7 @@
/// <param name="minute">The minute in which the schedule will be activated (0-59).</param>
public static string Daily(int hour, int minute)
{
return $"{minute} {hour} * * *";
return $"0 {minute} {hour} 1/1 * ? *";
}
/// <summary>
@ -114,7 +113,7 @@
/// <param name="minute">The minute in which the schedule will be activated (0-59).</param>
public static string Weekly(DayOfWeek dayOfWeek, int hour, int minute)
{
return $"{minute} {hour} * * {(int)dayOfWeek}";
return $"0 {minute} {hour} ? * {(int)dayOfWeek} *";
}
/// <summary>
@ -219,7 +218,7 @@
/// <param name="interval">The number of minutes to wait between every activation.</param>
public static string MinuteInterval(int interval)
{
return $"*/{interval} * * * *";
return $" 0 0/{interval} * 1/1 * ? *";
}
/// <summary>
@ -228,7 +227,7 @@
/// <param name="interval">The number of hours to wait between every activation.</param>
public static string HourInterval(int interval)
{
return $"0 */{interval} * * *";
return $"0 0 0/{interval} 1/1 * ? *";
}
/// <summary>
@ -237,7 +236,7 @@
/// <param name="interval">The number of days to wait between every activation.</param>
public static string DayInterval(int interval)
{
return $"0 0 */{interval} * *";
return $"0 0 12 1/{interval} * ? *";
}
/// <summary>
@ -249,4 +248,39 @@
return $"0 0 1 */{interval} *";
}
}
//
// Summary:
// Specifies the day of the week.
public enum DayOfWeek
{
//
// Summary:
// Indicates Sunday.
Sunday = 1,
//
// Summary:
// Indicates Monday.
Monday = 2,
//
// Summary:
// Indicates Tuesday.
Tuesday = 3,
//
// Summary:
// Indicates Wednesday.
Wednesday = 4,
//
// Summary:
// Indicates Thursday.
Thursday = 5,
//
// Summary:
// Indicates Friday.
Friday = 6,
//
// Summary:
// Indicates Saturday.
Saturday = 7
}
}

@ -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>(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>(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));

@ -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());
_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<MovieRequests> { 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<IQueryable<PlexEpisode>>(),It.IsAny<Expression<Func<PlexEpisode, PlexServerContent>>>()));
await Checker.Start();
await Checker.Execute(null);
_tv.Verify(x => x.Save(), Times.Once);

@ -0,0 +1,26 @@
using System;
using Quartz;
using Quartz.Spi;
namespace Ombi.Schedule
{
public class IoCJobFactory : IJobFactory
{
private readonly IServiceProvider _factory;
public IoCJobFactory(IServiceProvider factory)
{
_factory = factory;
}
public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler)
{
return _factory.GetService(bundle.JobDetail.JobType) as IJob;
}
public void ReturnJob(IJob job)
{
var disposable = job as IDisposable;
disposable?.Dispose();
}
}
}

@ -65,24 +65,24 @@ namespace Ombi.Schedule
{
var s = _jobSettings.GetSettings();
RecurringJob.AddOrUpdate(() => _embyContentSync.Start(), JobSettingsHelper.EmbyContent(s));
RecurringJob.AddOrUpdate(() => _sonarrSync.Start(), JobSettingsHelper.Sonarr(s));
RecurringJob.AddOrUpdate(() => _radarrSync.CacheContent(), JobSettingsHelper.Radarr(s));
RecurringJob.AddOrUpdate(() => _plexContentSync.CacheContent(false), JobSettingsHelper.PlexContent(s));
RecurringJob.AddOrUpdate(() => _plexRecentlyAddedSync.Start(), JobSettingsHelper.PlexRecentlyAdded(s));
RecurringJob.AddOrUpdate(() => _cpCache.Start(), JobSettingsHelper.CouchPotato(s));
RecurringJob.AddOrUpdate(() => _srSync.Start(), JobSettingsHelper.SickRageSync(s));
RecurringJob.AddOrUpdate(() => _refreshMetadata.Start(), JobSettingsHelper.RefreshMetadata(s));
RecurringJob.AddOrUpdate(() => _lidarrArtistSync.CacheContent(), JobSettingsHelper.LidarrArtistSync(s));
RecurringJob.AddOrUpdate(() => _issuesPurge.Start(), JobSettingsHelper.IssuePurge(s));
// RecurringJob.AddOrUpdate(() => _embyContentSync.Start(), JobSettingsHelper.EmbyContent(s));
// RecurringJob.AddOrUpdate(() => _sonarrSync.Start(), JobSettingsHelper.Sonarr(s));
// RecurringJob.AddOrUpdate(() => _radarrSync.CacheContent(), JobSettingsHelper.Radarr(s));
// //RecurringJob.AddOrUpdate(() => _plexContentSync.Execute(null), JobSettingsHelper.PlexContent(s));
// //RecurringJob.AddOrUpdate(() => _plexRecentlyAddedSync.Start(), JobSettingsHelper.PlexRecentlyAdded(s));
// RecurringJob.AddOrUpdate(() => _cpCache.Start(), JobSettingsHelper.CouchPotato(s));
// RecurringJob.AddOrUpdate(() => _srSync.Start(), JobSettingsHelper.SickRageSync(s));
// RecurringJob.AddOrUpdate(() => _refreshMetadata.Start(), JobSettingsHelper.RefreshMetadata(s));
// RecurringJob.AddOrUpdate(() => _lidarrArtistSync.CacheContent(), JobSettingsHelper.LidarrArtistSync(s));
// RecurringJob.AddOrUpdate(() => _issuesPurge.Start(), JobSettingsHelper.IssuePurge(s));
RecurringJob.AddOrUpdate(() => _updater.Update(null), JobSettingsHelper.Updater(s));
// RecurringJob.AddOrUpdate(() => _updater.Update(null), JobSettingsHelper.Updater(s));
RecurringJob.AddOrUpdate(() => _embyUserImporter.Start(), JobSettingsHelper.UserImporter(s));
RecurringJob.AddOrUpdate(() => _plexUserImporter.Start(), JobSettingsHelper.UserImporter(s));
RecurringJob.AddOrUpdate(() => _newsletter.Start(), JobSettingsHelper.Newsletter(s));
// RecurringJob.AddOrUpdate(() => _resender.Start(), JobSettingsHelper.ResendFailedRequests(s));
RecurringJob.AddOrUpdate(() => _mediaDatabaseRefresh.Start(), JobSettingsHelper.MediaDatabaseRefresh(s));
// RecurringJob.AddOrUpdate(() => _embyUserImporter.Start(), JobSettingsHelper.UserImporter(s));
// RecurringJob.AddOrUpdate(() => _plexUserImporter.Start(), JobSettingsHelper.UserImporter(s));
// RecurringJob.AddOrUpdate(() => _newsletter.Start(), JobSettingsHelper.Newsletter(s));
//// RecurringJob.AddOrUpdate(() => _resender.Start(), JobSettingsHelper.ResendFailedRequests(s));
// RecurringJob.AddOrUpdate(() => _mediaDatabaseRefresh.Start(), JobSettingsHelper.MediaDatabaseRefresh(s));
}
private bool _disposed;
@ -93,7 +93,6 @@ namespace Ombi.Schedule
if (disposing)
{
_plexContentSync?.Dispose();
_radarrSync?.Dispose();
_updater?.Dispose();
_plexUserImporter?.Dispose();

@ -36,6 +36,7 @@ using Ombi.Helpers;
using Ombi.Settings.Settings.Models.External;
using Ombi.Store.Context;
using Ombi.Store.Entities;
using Quartz;
namespace Ombi.Schedule.Jobs.Couchpotato
{
@ -56,7 +57,7 @@ namespace Ombi.Schedule.Jobs.Couchpotato
private readonly ILogger<CouchPotatoSync> _log;
private readonly IExternalContext _ctx;
public async Task Start()
public async Task Execute(IJobExecutionContext job)
{
var settings = await _settings.GetSettingsAsync();
if (!settings.Enabled)

@ -4,6 +4,5 @@ namespace Ombi.Schedule.Jobs.Couchpotato
{
public interface ICouchPotatoSync : IBaseJob
{
Task Start();
}
}

@ -37,6 +37,7 @@ using Ombi.Notifications.Models;
using Ombi.Store.Entities;
using Ombi.Store.Repository;
using Ombi.Store.Repository.Requests;
using Quartz;
namespace Ombi.Schedule.Jobs.Emby
{
@ -58,7 +59,7 @@ namespace Ombi.Schedule.Jobs.Emby
private readonly INotificationService _notificationService;
private readonly ILogger<EmbyAvaliabilityChecker> _log;
public async Task Start()
public async Task Execute(IJobExecutionContext job)
{
await ProcessMovies();
await ProcessTv();

@ -12,6 +12,7 @@ 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;
@ -20,25 +21,21 @@ namespace Ombi.Schedule.Jobs.Emby
public class EmbyContentSync : IEmbyContentSync
{
public EmbyContentSync(ISettingsService<EmbySettings> settings, IEmbyApi api, ILogger<EmbyContentSync> logger,
IEmbyContentRepository repo, IEmbyEpisodeSync epSync, IRefreshMetadata metadata)
IEmbyContentRepository repo)
{
_logger = logger;
_settings = settings;
_api = api;
_repo = repo;
_episodeSync = epSync;
_metadata = metadata;
}
private readonly ILogger<EmbyContentSync> _logger;
private readonly ISettingsService<EmbySettings> _settings;
private readonly IEmbyApi _api;
private readonly IEmbyContentRepository _repo;
private readonly IEmbyEpisodeSync _episodeSync;
private readonly IRefreshMetadata _metadata;
public async Task Start()
public async Task Execute(IJobExecutionContext job)
{
var embySettings = await _settings.GetSettingsAsync();
if (!embySettings.Enable)
@ -57,8 +54,12 @@ namespace Ombi.Schedule.Jobs.Emby
}
// Episodes
BackgroundJob.Enqueue(() => _episodeSync.Start());
BackgroundJob.Enqueue(() => _metadata.Start());
await OmbiQuartz.TriggerJob(nameof(IEmbyEpisodeSync));
await OmbiQuartz.TriggerJob(nameof(IRefreshMetadata));
//BackgroundJob.Enqueue(() => _episodeSync.Start());
//BackgroundJob.Enqueue(() => _metadata.Start());
}

@ -36,29 +36,27 @@ using Ombi.Core.Settings;
using Ombi.Core.Settings.Models.External;
using Ombi.Store.Entities;
using Ombi.Store.Repository;
using Quartz;
namespace Ombi.Schedule.Jobs.Emby
{
public class EmbyEpisodeSync : IEmbyEpisodeSync
{
public EmbyEpisodeSync(ISettingsService<EmbySettings> s, IEmbyApi api, ILogger<EmbyEpisodeSync> l, IEmbyContentRepository repo,
IEmbyAvaliabilityChecker checker)
public EmbyEpisodeSync(ISettingsService<EmbySettings> s, IEmbyApi api, ILogger<EmbyEpisodeSync> l, IEmbyContentRepository repo)
{
_api = api;
_logger = l;
_settings = s;
_repo = repo;
_avaliabilityChecker = checker;
}
private readonly ISettingsService<EmbySettings> _settings;
private readonly IEmbyApi _api;
private readonly ILogger<EmbyEpisodeSync> _logger;
private readonly IEmbyContentRepository _repo;
private readonly IEmbyAvaliabilityChecker _avaliabilityChecker;
public async Task Start()
public async Task Execute(IJobExecutionContext job)
{
var settings = await _settings.GetSettingsAsync();
@ -67,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)
@ -142,7 +141,6 @@ namespace Ombi.Schedule.Jobs.Emby
{
_settings?.Dispose();
_repo?.Dispose();
_avaliabilityChecker?.Dispose();
}
_disposed = true;
}

@ -37,6 +37,7 @@ using Ombi.Core.Settings.Models.External;
using Ombi.Helpers;
using Ombi.Settings.Settings.Models;
using Ombi.Store.Entities;
using Quartz;
namespace Ombi.Schedule.Jobs.Emby
{
@ -58,7 +59,7 @@ namespace Ombi.Schedule.Jobs.Emby
private readonly ISettingsService<EmbySettings> _embySettings;
private readonly ISettingsService<UserManagementSettings> _userManagementSettings;
public async Task Start()
public async Task Execute(IJobExecutionContext job)
{
var userManagementSettings = await _userManagementSettings.GetSettingsAsync();
if (!userManagementSettings.ImportEmbyUsers)

@ -4,6 +4,5 @@ namespace Ombi.Schedule.Jobs.Emby
{
public interface IEmbyAvaliabilityChecker : IBaseJob
{
Task Start();
}
}

@ -4,6 +4,5 @@ namespace Ombi.Schedule.Jobs.Emby
{
public interface IEmbyContentSync : IBaseJob
{
Task Start();
}
}

@ -4,6 +4,5 @@ namespace Ombi.Schedule.Jobs.Emby
{
public interface IEmbyEpisodeSync : IBaseJob
{
Task Start();
}
}

@ -4,6 +4,5 @@ namespace Ombi.Schedule.Jobs.Emby
{
public interface IEmbyUserImporter : IBaseJob
{
Task Start();
}
}

@ -25,11 +25,12 @@
// ************************************************************************/
#endregion
using Quartz;
using System;
namespace Ombi.Schedule
{
public interface IBaseJob : IDisposable
public interface IBaseJob : IJob, IDisposable
{
}

@ -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 ILidarrArtistSync
public interface ILidarrArtistSync : IJob
{
Task CacheContent();
void Dispose();
Task<IEnumerable<LidarrArtistCache>> GetCachedContent();
}

@ -11,6 +11,7 @@ using Ombi.Helpers;
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
@ -35,7 +36,7 @@ namespace Ombi.Schedule.Jobs.Lidarr
private readonly IBackgroundJobClient _job;
private readonly ILidarrAlbumSync _albumSync;
public async Task CacheContent()
public async Task Execute(IJobExecutionContext job)
{
try
{

@ -3,7 +3,6 @@
namespace Ombi.Schedule.Jobs.Ombi
{
public interface IIssuesPurge : IBaseJob
{
Task Start();
{
}
}

@ -4,6 +4,5 @@ namespace Ombi.Schedule.Jobs.Plex.Interfaces
{
public interface IMediaDatabaseRefresh : IBaseJob
{
Task Start();
}
}

@ -5,7 +5,6 @@ namespace Ombi.Schedule.Jobs.Ombi
{
public interface INewsletterJob : IBaseJob
{
Task Start();
Task Start(NewsletterSettings settings, bool test);
}
}

@ -5,7 +5,6 @@ namespace Ombi.Schedule.Jobs.Ombi
{
public interface IOmbiAutomaticUpdater : IBaseJob
{
Task Update(PerformContext context);
string[] GetVersion();
Task<bool> UpdateAvailable(string branch, string currentVersion);
}

@ -5,7 +5,6 @@ namespace Ombi.Schedule.Jobs.Ombi
{
public interface IRefreshMetadata : IBaseJob
{
Task Start();
Task ProcessPlexServerContent(IEnumerable<int> contentIds);
}
}

@ -1,9 +1,9 @@
using System.Threading.Tasks;
using Quartz;
using System.Threading.Tasks;
namespace Ombi.Schedule.Jobs.Ombi
{
public interface IResendFailedRequests
public interface IResendFailedRequests : IJob
{
Task Start();
}
}

@ -3,7 +3,7 @@ using Ombi.Store.Entities;
namespace Ombi.Schedule.Jobs.Ombi
{
public interface IWelcomeEmail : IBaseJob
public interface IWelcomeEmail
{
Task SendEmail(OmbiUser user);
}

@ -5,6 +5,7 @@ using Ombi.Core.Settings;
using Ombi.Settings.Settings.Models;
using Ombi.Store.Entities.Requests;
using Ombi.Store.Repository;
using Quartz;
namespace Ombi.Schedule.Jobs.Ombi
{
@ -20,7 +21,7 @@ namespace Ombi.Schedule.Jobs.Ombi
private readonly IRepository<Issues> _issuesRepository;
private readonly ISettingsService<IssueSettings> _settings;
public async Task Start()
public async Task Execute(IJobExecutionContext job)
{
var settings = await _settings.GetSettingsAsync();
if (!settings.DeleteIssues)

@ -9,19 +9,19 @@ using Ombi.Helpers;
using Ombi.Schedule.Jobs.Emby;
using Ombi.Schedule.Jobs.Plex.Interfaces;
using Ombi.Store.Repository;
using Quartz;
namespace Ombi.Schedule.Jobs.Ombi
{
public class MediaDatabaseRefresh : IMediaDatabaseRefresh
{
public MediaDatabaseRefresh(ISettingsService<PlexSettings> s, ILogger<MediaDatabaseRefresh> log,
IPlexContentRepository plexRepo, IEmbyContentRepository embyRepo, IEmbyContentSync embySync)
IPlexContentRepository plexRepo, IEmbyContentRepository embyRepo)
{
_settings = s;
_log = log;
_plexRepo = plexRepo;
_embyRepo = embyRepo;
_embyContentSync = embySync;
_settings.ClearCache();
}
@ -29,9 +29,8 @@ namespace Ombi.Schedule.Jobs.Ombi
private readonly ILogger _log;
private readonly IPlexContentRepository _plexRepo;
private readonly IEmbyContentRepository _embyRepo;
private readonly IEmbyContentSync _embyContentSync;
public async Task Start()
public async Task Execute(IJobExecutionContext job)
{
try
{
@ -60,7 +59,7 @@ namespace Ombi.Schedule.Jobs.Ombi
await _embyRepo.ExecuteSql(episodeSQL);
await _embyRepo.ExecuteSql(mainSql);
BackgroundJob.Enqueue(() => _embyContentSync.Start());
await OmbiQuartz.TriggerJob(nameof(IEmbyContentSync));
}
catch (Exception e)
{

@ -26,6 +26,7 @@ using Ombi.Settings.Settings.Models.External;
using Ombi.Settings.Settings.Models.Notifications;
using Ombi.Store.Entities;
using Ombi.Store.Repository;
using Quartz;
using ContentType = Ombi.Store.Entities.ContentType;
namespace Ombi.Schedule.Jobs.Ombi
@ -288,7 +289,7 @@ namespace Ombi.Schedule.Jobs.Ombi
}
}
public async Task Start()
public async Task Execute(IJobExecutionContext job)
{
var newsletterSettings = await _newsletterSettings.GetSettingsAsync();
await Start(newsletterSettings, false);

@ -20,6 +20,7 @@ using Ombi.Settings.Settings.Models;
using Ombi.Store.Entities;
using Ombi.Store.Repository;
using Ombi.Updater;
using Quartz;
using SharpCompress.Readers;
using SharpCompress.Readers.Tar;
@ -41,7 +42,6 @@ namespace Ombi.Schedule.Jobs.Ombi
private IChangeLogProcessor Processor { get; }
private ISettingsService<UpdateSettings> Settings { get; }
private readonly IProcessProvider _processProvider;
private static PerformContext Ctx { get; set; }
private readonly IApplicationConfigRepository _appConfig;
public string[] GetVersion()
@ -59,10 +59,8 @@ namespace Ombi.Schedule.Jobs.Ombi
}
[AutomaticRetry(Attempts = 1)]
public async Task Update(PerformContext c)
public async Task Execute(IJobExecutionContext job)
{
Ctx = c;
Logger.LogDebug(LoggingEvents.Updater, "Starting Update job");
var settings = await Settings.GetSettingsAsync();
@ -182,7 +180,7 @@ namespace Ombi.Schedule.Jobs.Ombi
}
Logger.LogDebug(LoggingEvents.Updater, "Starting Download");
await DownloadAsync(download.Url, zipDir, c);
await DownloadAsync(download.Url, zipDir);
Logger.LogDebug(LoggingEvents.Updater, "Finished Download");
}
catch (Exception e)
@ -321,7 +319,7 @@ namespace Ombi.Schedule.Jobs.Ombi
}
}
public async Task DownloadAsync(string requestUri, string filename, PerformContext ctx)
public async Task DownloadAsync(string requestUri, string filename)
{
Logger.LogDebug(LoggingEvents.Updater, "Starting the DownloadAsync");
using (var client = new WebClient())

@ -15,6 +15,7 @@ using Ombi.Schedule.Jobs.Emby;
using Ombi.Schedule.Jobs.Plex;
using Ombi.Store.Entities;
using Ombi.Store.Repository;
using Quartz;
namespace Ombi.Schedule.Jobs.Ombi
{
@ -22,8 +23,7 @@ namespace Ombi.Schedule.Jobs.Ombi
{
public RefreshMetadata(IPlexContentRepository plexRepo, IEmbyContentRepository embyRepo,
ILogger<RefreshMetadata> log, ITvMazeApi tvApi, ISettingsService<PlexSettings> plexSettings,
IMovieDbApi movieApi, ISettingsService<EmbySettings> embySettings, IPlexAvailabilityChecker plexAvailability, IEmbyAvaliabilityChecker embyAvaliability,
IEmbyApi embyApi)
IMovieDbApi movieApi, ISettingsService<EmbySettings> embySettings, IEmbyApi embyApi)
{
_plexRepo = plexRepo;
_embyRepo = embyRepo;
@ -32,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;
@ -48,7 +44,7 @@ namespace Ombi.Schedule.Jobs.Ombi
private readonly ISettingsService<EmbySettings> _embySettings;
private readonly IEmbyApi _embyApi;
public async Task Start()
public async Task Execute(IJobExecutionContext job)
{
_log.LogInformation("Starting the Metadata refresh");
try
@ -93,12 +89,12 @@ namespace Ombi.Schedule.Jobs.Ombi
{
if (plexSettings.Enable)
{
BackgroundJob.Enqueue(() => _plexAvailabilityChecker.Start());
await OmbiQuartz.TriggerJob(nameof(IPlexAvailabilityChecker));
}
if (embySettings.Enable)
{
BackgroundJob.Enqueue(() => _embyAvaliabilityChecker.Start());
await OmbiQuartz.TriggerJob(nameof(IEmbyAvaliabilityChecker));
}
}

@ -7,6 +7,7 @@ using Ombi.Core.Senders;
using Ombi.Store.Entities;
using Ombi.Store.Repository;
using Ombi.Store.Repository.Requests;
using Quartz;
namespace Ombi.Schedule.Jobs.Ombi
{
@ -32,7 +33,7 @@ namespace Ombi.Schedule.Jobs.Ombi
private readonly ITvRequestRepository _tvRequestRepository;
private readonly IMusicRequestRepository _musicRequestRepository;
public async Task Start()
public async Task Execute(IJobExecutionContext job)
{
// Get all the failed ones!
var failedRequests = _requestQueue.GetAll().Where(x => !x.Completed.HasValue);

@ -5,6 +5,5 @@ namespace Ombi.Schedule.Jobs.Plex
{
public interface IPlexAvailabilityChecker : IBaseJob
{
Task Start();
}
}

@ -1,9 +1,9 @@
using System.Threading.Tasks;
using Quartz;
namespace Ombi.Schedule.Jobs
{
public interface IPlexContentSync : IBaseJob
public interface IPlexContentSync : IJob
{
Task CacheContent(bool recentlyAddedSearch = false);
}
}

@ -9,7 +9,6 @@ namespace Ombi.Schedule.Jobs.Plex.Interfaces
{
public interface IPlexEpisodeSync : IBaseJob
{
Task Start();
Task<HashSet<PlexEpisode>> ProcessEpsiodes(Metadata[] episodes, IQueryable<PlexEpisode> currentEpisodes);
}
}

@ -4,6 +4,5 @@ namespace Ombi.Schedule.Jobs.Plex
{
public interface IPlexUserImporter : IBaseJob
{
Task Start();
}
}

@ -12,6 +12,7 @@ using Ombi.Store.Entities;
using Ombi.Store.Entities.Requests;
using Ombi.Store.Repository;
using Ombi.Store.Repository.Requests;
using Quartz;
namespace Ombi.Schedule.Jobs.Plex
{
@ -35,7 +36,7 @@ namespace Ombi.Schedule.Jobs.Plex
private readonly IBackgroundJobClient _backgroundJobClient;
private readonly ILogger _log;
public async Task Start()
public async Task Execute(IJobExecutionContext job)
{
try
{

@ -42,13 +42,14 @@ using Ombi.Schedule.Jobs.Plex.Interfaces;
using Ombi.Schedule.Jobs.Plex.Models;
using Ombi.Store.Entities;
using Ombi.Store.Repository;
using Quartz;
namespace Ombi.Schedule.Jobs.Plex
{
public class PlexContentSync : IPlexContentSync
{
public PlexContentSync(ISettingsService<PlexSettings> plex, IPlexApi plexApi, ILogger<PlexContentSync> logger, IPlexContentRepository repo,
IPlexEpisodeSync epsiodeSync, IRefreshMetadata metadataRefresh, IPlexAvailabilityChecker checker)
IPlexEpisodeSync epsiodeSync, IRefreshMetadata metadataRefresh)
{
Plex = plex;
PlexApi = plexApi;
@ -56,7 +57,6 @@ namespace Ombi.Schedule.Jobs.Plex
Repo = repo;
EpisodeSync = epsiodeSync;
Metadata = metadataRefresh;
Checker = checker;
Plex.ClearCache();
}
@ -66,10 +66,12 @@ namespace Ombi.Schedule.Jobs.Plex
private IPlexContentRepository Repo { get; }
private IPlexEpisodeSync EpisodeSync { get; }
private IRefreshMetadata Metadata { get; }
private IPlexAvailabilityChecker Checker { get; }
public async Task CacheContent(bool recentlyAddedSearch = false)
public async Task Execute(IJobExecutionContext context)
{
JobDataMap dataMap = context.JobDetail.JobDataMap;
var recentlyAddedSearch = dataMap.GetBooleanValueFromString("recentlyAddedSearch");
var plexSettings = await Plex.GetSettingsAsync();
if (!plexSettings.Enable)
{
@ -101,7 +103,8 @@ namespace Ombi.Schedule.Jobs.Plex
if (!recentlyAddedSearch)
{
Logger.LogInformation("Starting EP Cacher");
BackgroundJob.Enqueue(() => EpisodeSync.Start());
await OmbiQuartz.TriggerJob(nameof(IPlexEpisodeSync));
}
if ((processedContent?.HasProcessedContent ?? false) && recentlyAddedSearch)
@ -112,7 +115,8 @@ namespace Ombi.Schedule.Jobs.Plex
if ((processedContent?.HasProcessedEpisodes ?? false) && recentlyAddedSearch)
{
BackgroundJob.Enqueue(() => Checker.Start());
await OmbiQuartz.TriggerJob(nameof(IPlexAvailabilityChecker));
}
}

@ -13,19 +13,19 @@ using Ombi.Helpers;
using Ombi.Schedule.Jobs.Plex.Interfaces;
using Ombi.Store.Entities;
using Ombi.Store.Repository;
using Quartz;
namespace Ombi.Schedule.Jobs.Plex
{
public class PlexEpisodeSync : IPlexEpisodeSync
{
public PlexEpisodeSync(ISettingsService<PlexSettings> s, ILogger<PlexEpisodeSync> log, IPlexApi plexApi,
IPlexContentRepository repo, IPlexAvailabilityChecker a)
IPlexContentRepository repo)
{
_settings = s;
_log = log;
_api = plexApi;
_repo = repo;
_availabilityChecker = a;
_settings.ClearCache();
}
@ -33,9 +33,8 @@ namespace Ombi.Schedule.Jobs.Plex
private readonly ILogger<PlexEpisodeSync> _log;
private readonly IPlexApi _api;
private readonly IPlexContentRepository _repo;
private readonly IPlexAvailabilityChecker _availabilityChecker;
public async Task Start()
public async Task Execute(IJobExecutionContext job)
{
try
{
@ -56,7 +55,9 @@ namespace Ombi.Schedule.Jobs.Plex
_log.LogError(LoggingEvents.Cacher, e, "Caching Episodes Failed");
}
BackgroundJob.Enqueue(() => _availabilityChecker.Start());
await OmbiQuartz.TriggerJob(nameof(IPlexAvailabilityChecker));
//BackgroundJob.Enqueue(() => _availabilityChecker.Start()); // TODO
}
private async Task Cache(PlexServers settings)

@ -1,40 +1,40 @@
using System;
using System.Threading.Tasks;
using Hangfire;
//using System;
//using System.Threading.Tasks;
//using Hangfire;
namespace Ombi.Schedule.Jobs.Plex
{
public class PlexRecentlyAddedSync : IPlexRecentlyAddedSync
{
public PlexRecentlyAddedSync(IPlexContentSync sync)
{
_sync = sync;
}
//namespace Ombi.Schedule.Jobs.Plex
//{
// public class PlexRecentlyAddedSync : IPlexRecentlyAddedSync
// {
// public PlexRecentlyAddedSync(IPlexContentSync sync)
// {
// _sync = sync;
// }
private readonly IPlexContentSync _sync;
// private readonly IPlexContentSync _sync;
public void Start()
{
BackgroundJob.Enqueue(() => _sync.CacheContent(true));
}
// public void Start()
// {
// BackgroundJob.Enqueue(() => _sync.CacheContent(true));
// }
private bool _disposed;
protected virtual void Dispose(bool disposing)
{
if (_disposed)
return;
// private bool _disposed;
// protected virtual void Dispose(bool disposing)
// {
// if (_disposed)
// return;
if (disposing)
{
_sync?.Dispose();
}
_disposed = true;
}
// if (disposing)
// {
// _sync?.Dispose();
// }
// _disposed = true;
// }
public void Dispose()
{
Dispose(true);
GC.SuppressFinalize(this);
}
}
}
// public void Dispose()
// {
// Dispose(true);
// GC.SuppressFinalize(this);
// }
// }
//}

@ -11,6 +11,7 @@ using Ombi.Core.Settings.Models.External;
using Ombi.Helpers;
using Ombi.Settings.Settings.Models;
using Ombi.Store.Entities;
using Quartz;
namespace Ombi.Schedule.Jobs.Plex
{
@ -35,7 +36,7 @@ namespace Ombi.Schedule.Jobs.Plex
private readonly ISettingsService<UserManagementSettings> _userManagementSettings;
public async Task Start()
public async Task Execute(IJobExecutionContext job)
{
var userManagementSettings = await _userManagementSettings.GetSettingsAsync();
if (!userManagementSettings.ImportPlexUsers)

@ -6,7 +6,6 @@ namespace Ombi.Schedule.Jobs.Radarr
{
public interface IRadarrSync : IBaseJob
{
Task CacheContent();
Task<IEnumerable<RadarrCache>> GetCachedContent();
}
}

@ -10,6 +10,7 @@ using Ombi.Helpers;
using Ombi.Settings.Settings.Models.External;
using Ombi.Store.Context;
using Ombi.Store.Entities;
using Quartz;
using Serilog;
namespace Ombi.Schedule.Jobs.Radarr
@ -32,7 +33,7 @@ namespace Ombi.Schedule.Jobs.Radarr
private static readonly SemaphoreSlim SemaphoreSlim = new SemaphoreSlim(1, 1);
public async Task CacheContent()
public async Task Execute(IJobExecutionContext job)
{
await SemaphoreSlim.WaitAsync();
try

@ -4,6 +4,5 @@ namespace Ombi.Schedule.Jobs.SickRage
{
public interface ISickRageSync : IBaseJob
{
Task Start();
}
}

@ -11,6 +11,7 @@ using Ombi.Helpers;
using Ombi.Settings.Settings.Models.External;
using Ombi.Store.Context;
using Ombi.Store.Entities;
using Quartz;
namespace Ombi.Schedule.Jobs.SickRage
{
@ -30,7 +31,7 @@ namespace Ombi.Schedule.Jobs.SickRage
private readonly ILogger<SickRageSync> _log;
private readonly IExternalContext _ctx;
public async Task Start()
public async Task Execute(IJobExecutionContext job)
{
try
{

@ -4,6 +4,5 @@ namespace Ombi.Schedule.Jobs.Sonarr
{
public interface ISonarrSync : IBaseJob
{
Task Start();
}
}

@ -14,6 +14,7 @@ using Ombi.Helpers;
using Ombi.Settings.Settings.Models.External;
using Ombi.Store.Context;
using Ombi.Store.Entities;
using Quartz;
namespace Ombi.Schedule.Jobs.Sonarr
{
@ -33,7 +34,7 @@ namespace Ombi.Schedule.Jobs.Sonarr
private readonly ILogger<SonarrSync> _log;
private readonly IExternalContext _ctx;
public async Task Start()
public async Task Execute(IJobExecutionContext job)
{
try
{

@ -17,6 +17,7 @@
<PackageReference Include="Hangfire.RecurringJobExtensions" Version="1.1.6" />
<PackageReference Include="Hangfire.SQLite" Version="1.4.2" />
<PackageReference Include="Serilog" Version="2.7.1" />
<PackageReference Include="Quartz" Version="3.0.7" />
<PackageReference Include="SharpCompress" Version="0.18.2" />
<PackageReference Include="System.Diagnostics.Process" Version="4.3.0" />
<PackageReference Include="HtmlAgilityPack" Version="1.6.13" />

@ -0,0 +1,72 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Quartz;
using Quartz.Impl;
using Quartz.Spi;
namespace Ombi.Schedule
{
public class OmbiQuartz
{
protected IScheduler _scheduler { get; set; }
public static IScheduler Scheduler => Instance._scheduler;
// Singleton
protected static OmbiQuartz _instance;
/// <summary>
/// Singleton
/// </summary>
public static OmbiQuartz Instance => _instance ?? (_instance = new OmbiQuartz());
protected OmbiQuartz()
{
Init();
}
private async void Init()
{
_scheduler = await new StdSchedulerFactory().GetScheduler();
}
public IScheduler UseJobFactory(IJobFactory jobFactory)
{
Scheduler.JobFactory = jobFactory;
return Scheduler;
}
public async Task AddJob<T>(string name, string group, string cronExpression, Dictionary<string, string> jobData = null)
where T : IJob
{
var jobBuilder = JobBuilder.Create<T>()
.WithIdentity(name, group);
if (jobData != null)
{
foreach (var o in jobData)
{
jobBuilder.UsingJobData(o.Key, o.Value);
}
}
var job = jobBuilder.Build();
ITrigger jobTrigger = TriggerBuilder.Create()
.WithIdentity(name + "Trigger", group)
.WithCronSchedule(cronExpression)
.Build();
await Scheduler.ScheduleJob(job, jobTrigger);
}
public static async Task TriggerJob(string jobName)
{
await Scheduler.TriggerJob(new JobKey(jobName));
}
public static async Task Start()
{
await Scheduler.Start();
}
}
}

@ -0,0 +1,95 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Ombi.Core.Settings;
using Ombi.Schedule.Jobs;
using Ombi.Schedule.Jobs.Couchpotato;
using Ombi.Schedule.Jobs.Emby;
using Ombi.Schedule.Jobs.Lidarr;
using Ombi.Schedule.Jobs.Ombi;
using Ombi.Schedule.Jobs.Plex;
using Ombi.Schedule.Jobs.Plex.Interfaces;
using Ombi.Schedule.Jobs.Radarr;
using Ombi.Schedule.Jobs.SickRage;
using Ombi.Schedule.Jobs.Sonarr;
using Ombi.Settings.Settings.Models;
using Quartz;
using Quartz.Spi;
namespace Ombi.Schedule
{
public static class OmbiScheduler
{
//public void Setup()
//{
// CreateJobDefinitions();
//}
//public void CreateJobDefinitions()
//{
// var contentSync = JobBuilder.Create<PlexContentSync>()
// .UsingJobData("recentlyAddedSearch", false)
// .WithIdentity(nameof(PlexContentSync), "Plex")
// .Build();
// var recentlyAdded = JobBuilder.Create<PlexContentSync>()
// .UsingJobData("recentlyAddedSearch", true)
// .WithIdentity("PlexRecentlyAdded", "Plex")
// .Build();
//}
public static async Task UseQuartz(this IApplicationBuilder app)
{
// Job Factory through IOC container
var jobFactory = (IJobFactory)app.ApplicationServices.GetService(typeof(IJobFactory));
var service = (ISettingsService<JobSettings>)app.ApplicationServices.GetService(typeof(ISettingsService<JobSettings>));
var s = service.GetSettings();
// Set job factory
OmbiQuartz.Instance.UseJobFactory(jobFactory);
// Run Quartz
await OmbiQuartz.Start();
// Run configuration
await AddPlex(s);
await AddEmby(s);
await AddDvrApps(s);
await AddSystem(s);
}
private static async Task AddSystem(JobSettings s)
{
await OmbiQuartz.Instance.AddJob<IRefreshMetadata>(nameof(IRefreshMetadata), "System", JobSettingsHelper.RefreshMetadata(s));
await OmbiQuartz.Instance.AddJob<IIssuesPurge>(nameof(IIssuesPurge), "System", JobSettingsHelper.IssuePurge(s));
//OmbiQuartz.Instance.AddJob<IOmbiAutomaticUpdater>(nameof(IOmbiAutomaticUpdater), "System", JobSettingsHelper.Updater(s));
await OmbiQuartz.Instance.AddJob<INewsletterJob>(nameof(INewsletterJob), "System", JobSettingsHelper.Newsletter(s));
await OmbiQuartz.Instance.AddJob<IResendFailedRequests>(nameof(IResendFailedRequests), "System", JobSettingsHelper.ResendFailedRequests(s));
await OmbiQuartz.Instance.AddJob<IMediaDatabaseRefresh>(nameof(IMediaDatabaseRefresh), "System", JobSettingsHelper.MediaDatabaseRefresh(s));
}
private static async Task AddDvrApps(JobSettings s)
{
await OmbiQuartz.Instance.AddJob<ISonarrSync>(nameof(ISonarrSync), "DVR", JobSettingsHelper.Sonarr(s));
await OmbiQuartz.Instance.AddJob<IRadarrSync>(nameof(IRadarrSync), "DVR", JobSettingsHelper.Radarr(s));
await OmbiQuartz.Instance.AddJob<ICouchPotatoSync>(nameof(ICouchPotatoSync), "DVR", JobSettingsHelper.CouchPotato(s));
await OmbiQuartz.Instance.AddJob<ISickRageSync>(nameof(ISickRageSync), "DVR", JobSettingsHelper.SickRageSync(s));
await OmbiQuartz.Instance.AddJob<ILidarrArtistSync>(nameof(ILidarrArtistSync), "DVR", JobSettingsHelper.LidarrArtistSync(s));
}
private static async Task AddPlex(JobSettings s)
{
await OmbiQuartz.Instance.AddJob<IPlexContentSync>(nameof(IPlexContentSync), "Plex", JobSettingsHelper.PlexContent(s), new Dictionary<string, string> { { "recentlyAddedSearch", "false" } });
await OmbiQuartz.Instance.AddJob<IPlexContentSync>(nameof(IPlexContentSync) + "RecentlyAdded", "Plex", JobSettingsHelper.PlexContent(s), new Dictionary<string, string> { { "recentlyAddedSearch", "true" } });
await OmbiQuartz.Instance.AddJob<IPlexRecentlyAddedSync>(nameof(IPlexRecentlyAddedSync), "Plex", JobSettingsHelper.PlexRecentlyAdded(s));
await OmbiQuartz.Instance.AddJob<IPlexUserImporter>(nameof(IPlexUserImporter), "Plex", JobSettingsHelper.UserImporter(s));
}
private static async Task AddEmby(JobSettings s)
{
await OmbiQuartz.Instance.AddJob<IEmbyContentSync>(nameof(IEmbyContentSync), "Emby", JobSettingsHelper.EmbyContent(s));
await OmbiQuartz.Instance.AddJob<IEmbyUserImporter>(nameof(IEmbyUserImporter), "Emby", JobSettingsHelper.UserImporter(s));
}
}
}

@ -10,6 +10,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" />
<PackageReference Include="Quartz" Version="3.0.7" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
</ItemGroup>

@ -1,5 +1,6 @@
using System;
using Ombi.Helpers;
using Quartz;
namespace Ombi.Settings.Settings.Models
{
@ -7,71 +8,93 @@ namespace Ombi.Settings.Settings.Models
{
public static string Radarr(JobSettings s)
{
return Get(s.RadarrSync, Cron.Hourly(15));
return ValidateCron(Get(s.RadarrSync, Cron.Hourly(15)));
}
public static string Sonarr(JobSettings s)
{
return Get(s.SonarrSync, Cron.Hourly(10));
return ValidateCron(Get(s.SonarrSync, Cron.Hourly(10)));
}
public static string EmbyContent(JobSettings s)
{
return Get(s.EmbyContentSync, Cron.Hourly(5));
return ValidateCron(Get(s.EmbyContentSync, Cron.Hourly(5)));
}
public static string PlexContent(JobSettings s)
{
return Get(s.PlexContentSync, Cron.Daily(2));
return ValidateCron(Get(s.PlexContentSync, Cron.Daily(2)));
}
public static string PlexRecentlyAdded(JobSettings s)
{
return Get(s.PlexRecentlyAddedSync, Cron.MinuteInterval(30));
return ValidateCron(Get(s.PlexRecentlyAddedSync, Cron.MinuteInterval(30)));
}
public static string CouchPotato(JobSettings s)
{
return Get(s.CouchPotatoSync, Cron.Hourly(30));
return ValidateCron(Get(s.CouchPotatoSync, Cron.Hourly(30)));
}
public static string Updater(JobSettings s)
{
return Get(s.AutomaticUpdater, Cron.HourInterval(6));
return ValidateCron(Get(s.AutomaticUpdater, Cron.HourInterval(6)));
}
public static string UserImporter(JobSettings s)
{
return Get(s.UserImporter, Cron.Daily());
return ValidateCron(Get(s.UserImporter, Cron.Daily()));
}
public static string Newsletter(JobSettings s)
{
return Get(s.Newsletter, Cron.Weekly(DayOfWeek.Friday, 12));
return ValidateCron(Get(s.Newsletter, Cron.Weekly(Helpers.DayOfWeek.Friday, 12)));
}
public static string SickRageSync(JobSettings s)
{
return Get(s.SickRageSync, Cron.Hourly(35));
return ValidateCron(Get(s.SickRageSync, Cron.Hourly(35)));
}
public static string RefreshMetadata(JobSettings s)
{
return Get(s.RefreshMetadata, Cron.DayInterval(3));
return ValidateCron(Get(s.RefreshMetadata, Cron.DayInterval(3)));
}
public static string LidarrArtistSync(JobSettings s)
{
return Get(s.LidarrArtistSync, Cron.Hourly(40));
return ValidateCron(Get(s.LidarrArtistSync, Cron.Hourly(40)));
}
public static string IssuePurge(JobSettings s)
{
return Get(s.IssuesPurge, Cron.Daily());
return ValidateCron(Get(s.IssuesPurge, Cron.Daily()));
}
public static string ResendFailedRequests(JobSettings s)
{
return Get(s.RetryRequests, Cron.Daily(6));
return ValidateCron(Get(s.RetryRequests, Cron.Daily(6)));
}
public static string MediaDatabaseRefresh(JobSettings s)
{
return Get(s.MediaDatabaseRefresh, Cron.DayInterval(5));
return ValidateCron(Get(s.MediaDatabaseRefresh, Cron.DayInterval(5)));
}
private static string Get(string settings, string defaultCron)
{
return settings.HasValue() ? settings : defaultCron;
}
private const string _defaultCron = "0 0 12 1/1 * ? *";
private static string ValidateCron(string cron)
{
if (CronExpression.IsValidExpression(cron))
{
return cron;
}
return _defaultCron;
}
}
}

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Hangfire;
using Microsoft.AspNetCore.Mvc;
@ -6,10 +7,12 @@ 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;
using Ombi.Schedule.Jobs.Plex;
using Quartz;
namespace Ombi.Controllers
{
@ -19,35 +22,23 @@ namespace Ombi.Controllers
[ApiController]
public class JobController : ControllerBase
{
public JobController(IOmbiAutomaticUpdater updater, IPlexUserImporter userImporter,
ICacheService mem, IEmbyUserImporter embyImporter, IPlexContentSync plexContentSync,
IEmbyContentSync embyContentSync, INewsletterJob newsletter)
public JobController(IOmbiAutomaticUpdater updater, ICacheService mem)
{
_updater = updater;
_plexUserImporter = userImporter;
_embyUserImporter = embyImporter;
_memCache = mem;
_plexContentSync = plexContentSync;
_embyContentSync = embyContentSync;
_newsletterJob = newsletter;
}
private readonly IOmbiAutomaticUpdater _updater;
private readonly IPlexUserImporter _plexUserImporter;
private readonly IEmbyUserImporter _embyUserImporter;
private readonly ICacheService _memCache;
private readonly IPlexContentSync _plexContentSync;
private readonly IEmbyContentSync _embyContentSync;
private readonly INewsletterJob _newsletterJob;
/// <summary>
/// Runs the update job
/// </summary>
/// <returns></returns>
[HttpPost("update")]
public bool ForceUpdate()
public async Task<bool> ForceUpdate()
{
BackgroundJob.Enqueue(() => _updater.Update(null));
await OmbiQuartz.TriggerJob(nameof(IOmbiAutomaticUpdater));
return true;
}
@ -94,9 +85,9 @@ namespace Ombi.Controllers
/// </summary>
/// <returns></returns>
[HttpPost("plexuserimporter")]
public bool PlexUserImporter()
public async Task<bool> PlexUserImporter()
{
BackgroundJob.Enqueue(() => _plexUserImporter.Start());
await OmbiQuartz.TriggerJob(nameof(IPlexUserImporter));
return true;
}
@ -105,9 +96,9 @@ namespace Ombi.Controllers
/// </summary>
/// <returns></returns>
[HttpPost("embyuserimporter")]
public bool EmbyUserImporter()
public async Task<bool> EmbyUserImporter()
{
BackgroundJob.Enqueue(() => _embyUserImporter.Start());
await OmbiQuartz.TriggerJob(nameof(IEmbyUserImporter));
return true;
}
@ -118,7 +109,7 @@ namespace Ombi.Controllers
[HttpPost("plexcontentcacher")]
public bool StartPlexContentCacher()
{
BackgroundJob.Enqueue(() => _plexContentSync.CacheContent(false));
OmbiQuartz.Scheduler.TriggerJob(new JobKey(nameof(PlexContentSync)), new JobDataMap(new Dictionary<string, string> { { "recentlyAddedSearch", "false" } }));
return true;
}
@ -129,7 +120,7 @@ namespace Ombi.Controllers
[HttpPost("plexrecentlyadded")]
public bool StartRecentlyAdded()
{
BackgroundJob.Enqueue(() => _plexContentSync.CacheContent(true));
OmbiQuartz.Scheduler.TriggerJob(new JobKey(nameof(PlexContentSync)), new JobDataMap(new Dictionary<string, string> { { "recentlyAddedSearch", "true" } }));
return true;
}
@ -138,9 +129,9 @@ namespace Ombi.Controllers
/// </summary>
/// <returns></returns>
[HttpPost("embycontentcacher")]
public bool StartEmbyContentCacher()
public async Task<bool> StartEmbyContentCacher()
{
BackgroundJob.Enqueue(() => _embyContentSync.Start());
await OmbiQuartz.TriggerJob(nameof(IEmbyContentSync));
return true;
}
@ -149,9 +140,9 @@ namespace Ombi.Controllers
/// </summary>
/// <returns></returns>
[HttpPost("newsletter")]
public bool StartNewsletter()
public async Task<bool> StartNewsletter()
{
BackgroundJob.Enqueue(() => _newsletterJob.Start());
await OmbiQuartz.TriggerJob(nameof(INewsletterJob));
return true;
}
}

@ -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());
await OmbiQuartz.TriggerJob(nameof(IRadarrSync));
}
return result;
}

@ -123,6 +123,8 @@ namespace Ombi
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});
app.UseQuartz().GetAwaiter().GetResult();
var ctx = serviceProvider.GetService<IOmbiContext>();
loggerFactory.AddSerilog();
@ -190,8 +192,8 @@ namespace Ombi
GlobalJobFilters.Filters.Add(new AutomaticRetryAttribute { Attempts = 3 });
// Setup the scheduler
var jobSetup = app.ApplicationServices.GetService<IJobSetup>();
jobSetup.Setup();
//var jobSetup = app.ApplicationServices.GetService<IJobSetup>();
//jobSetup.Setup();
ctx.Seed();
var settingsctx = serviceProvider.GetService<ISettingsContext>();
var externalctx = serviceProvider.GetService<IExternalContext>();

Loading…
Cancel
Save