Fixed the scheduler!

pull/2947/head
tidusjar 6 years ago
parent 2789c9b452
commit 8f50213867

@ -19,7 +19,7 @@ namespace Ombi.Schedule.Tests
It.IsAny<CancellationToken>()));
var sut = new QuartzMock(scheduleMock);
await QuartzMock.TriggerJob("ABC");
//await QuartzMock.TriggerJob("ABC");
scheduleMock.Verify(x => x.TriggerJob(It.Is<JobKey>(j => j.Name == "ABC"),
default(CancellationToken)), Times.Once);

@ -1,4 +1,5 @@
using System;
using Microsoft.Extensions.DependencyInjection;
using Quartz;
using Quartz.Spi;
@ -14,7 +15,12 @@ namespace Ombi.Schedule
}
public IJob NewJob(TriggerFiredBundle bundle, IScheduler scheduler)
{
return _factory.GetService(bundle.JobDetail.JobType) as IJob;
var scopeFactory = _factory.GetService<IServiceScopeFactory>();
var scope = scopeFactory.CreateScope();
var scopedContainer = scope.ServiceProvider;
var implementation = scopedContainer.GetRequiredService(bundle.JobDetail.JobType) as IJob;
return implementation;
}
public void ReturnJob(IJob job)

@ -55,11 +55,8 @@ namespace Ombi.Schedule.Jobs.Emby
// Episodes
await OmbiQuartz.TriggerJob(nameof(IEmbyEpisodeSync));
await OmbiQuartz.TriggerJob(nameof(IRefreshMetadata));
//BackgroundJob.Enqueue(() => _episodeSync.Start());
//BackgroundJob.Enqueue(() => _metadata.Start());
await OmbiQuartz.TriggerJob(nameof(IEmbyEpisodeSync), "Emby");
await OmbiQuartz.TriggerJob(nameof(IRefreshMetadata), "Emby");
}

@ -66,7 +66,7 @@ namespace Ombi.Schedule.Jobs.Emby
}
await OmbiQuartz.TriggerJob(nameof(IEmbyAvaliabilityChecker));
await OmbiQuartz.TriggerJob(nameof(IEmbyAvaliabilityChecker), "Emby");
}
private async Task CacheEpisodes(EmbyServers server)

@ -59,7 +59,7 @@ namespace Ombi.Schedule.Jobs.Ombi
await _embyRepo.ExecuteSql(episodeSQL);
await _embyRepo.ExecuteSql(mainSql);
await OmbiQuartz.TriggerJob(nameof(IEmbyContentSync));
await OmbiQuartz.TriggerJob(nameof(IEmbyContentSync), "Emby");
}
catch (Exception e)
{

@ -89,12 +89,12 @@ namespace Ombi.Schedule.Jobs.Ombi
{
if (plexSettings.Enable)
{
await OmbiQuartz.TriggerJob(nameof(IPlexAvailabilityChecker));
await OmbiQuartz.TriggerJob(nameof(IPlexAvailabilityChecker), "Plex");
}
if (embySettings.Enable)
{
await OmbiQuartz.TriggerJob(nameof(IEmbyAvaliabilityChecker));
await OmbiQuartz.TriggerJob(nameof(IEmbyAvaliabilityChecker), "Emby");
}
}

@ -104,19 +104,19 @@ namespace Ombi.Schedule.Jobs.Plex
{
Logger.LogInformation("Starting EP Cacher");
await OmbiQuartz.TriggerJob(nameof(IPlexEpisodeSync));
await OmbiQuartz.TriggerJob(nameof(IPlexEpisodeSync), "Plex");
}
if ((processedContent?.HasProcessedContent ?? false) && recentlyAddedSearch)
{
// Just check what we send it
BackgroundJob.Enqueue(() => Metadata.ProcessPlexServerContent(processedContent.Content));
await OmbiQuartz.TriggerJob(nameof(IMediaDatabaseRefresh), "System");
}
if ((processedContent?.HasProcessedEpisodes ?? false) && recentlyAddedSearch)
{
await OmbiQuartz.TriggerJob(nameof(IPlexAvailabilityChecker));
await OmbiQuartz.TriggerJob(nameof(IPlexAvailabilityChecker), "Plex");
}
}

@ -56,8 +56,7 @@ namespace Ombi.Schedule.Jobs.Plex
}
await OmbiQuartz.TriggerJob(nameof(IPlexAvailabilityChecker));
//BackgroundJob.Enqueue(() => _availabilityChecker.Start()); // TODO
await OmbiQuartz.TriggerJob(nameof(IPlexAvailabilityChecker), "Plex");
}
private async Task Cache(PlexServers settings)

@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Ombi.Helpers;
using Quartz;
using Quartz.Impl;
using Quartz.Spi;
@ -40,7 +41,7 @@ namespace Ombi.Schedule
where T : IJob
{
var jobBuilder = JobBuilder.Create<T>()
.WithIdentity(name, group);
.WithIdentity(new JobKey(name, group));
if (jobData != null)
{
foreach (var o in jobData)
@ -49,19 +50,30 @@ namespace Ombi.Schedule
}
}
var job = jobBuilder.Build();
ITrigger jobTrigger = TriggerBuilder.Create()
.WithIdentity(name + "Trigger", group)
.WithCronSchedule(cronExpression)
.Build();
if(!cronExpression.HasValue())
{
jobBuilder.StoreDurably(true);
}
var job = jobBuilder.Build();
if (cronExpression.HasValue())
{
ITrigger jobTrigger = TriggerBuilder.Create()
.WithIdentity(name + "Trigger", group)
.WithCronSchedule(cronExpression)
.Build();
await Scheduler.ScheduleJob(job, jobTrigger);
}
else
{
await Scheduler.AddJob(job, true);
}
await Scheduler.ScheduleJob(job, jobTrigger);
}
public static async Task TriggerJob(string jobName)
public static async Task TriggerJob(string jobName, string group)
{
await Scheduler.TriggerJob(new JobKey(jobName));
await Scheduler.TriggerJob(new JobKey(jobName, group));
}
public static async Task Start()

@ -84,11 +84,15 @@ namespace Ombi.Schedule
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));
await OmbiQuartz.Instance.AddJob<IPlexEpisodeSync>(nameof(IPlexEpisodeSync), "Plex", null);
await OmbiQuartz.Instance.AddJob<IPlexAvailabilityChecker>(nameof(IPlexAvailabilityChecker), "Plex", null);
}
private static async Task AddEmby(JobSettings s)
{
await OmbiQuartz.Instance.AddJob<IEmbyContentSync>(nameof(IEmbyContentSync), "Emby", JobSettingsHelper.EmbyContent(s));
await OmbiQuartz.Instance.AddJob<IEmbyEpisodeSync>(nameof(IEmbyEpisodeSync), "Emby", null);
await OmbiQuartz.Instance.AddJob<IEmbyAvaliabilityChecker>(nameof(IEmbyAvaliabilityChecker), "Emby", null);
await OmbiQuartz.Instance.AddJob<IEmbyUserImporter>(nameof(IEmbyUserImporter), "Emby", JobSettingsHelper.UserImporter(s));
}
}

@ -38,7 +38,7 @@ namespace Ombi.Controllers
public async Task<bool> ForceUpdate()
{
await OmbiQuartz.TriggerJob(nameof(IOmbiAutomaticUpdater));
await OmbiQuartz.TriggerJob(nameof(IOmbiAutomaticUpdater), "System");
return true;
}
@ -87,7 +87,7 @@ namespace Ombi.Controllers
[HttpPost("plexuserimporter")]
public async Task<bool> PlexUserImporter()
{
await OmbiQuartz.TriggerJob(nameof(IPlexUserImporter));
await OmbiQuartz.TriggerJob(nameof(IPlexUserImporter), "Plex");
return true;
}
@ -98,7 +98,7 @@ namespace Ombi.Controllers
[HttpPost("embyuserimporter")]
public async Task<bool> EmbyUserImporter()
{
await OmbiQuartz.TriggerJob(nameof(IEmbyUserImporter));
await OmbiQuartz.TriggerJob(nameof(IEmbyUserImporter), "Emby");
return true;
}
@ -109,8 +109,7 @@ namespace Ombi.Controllers
[HttpPost("plexcontentcacher")]
public bool StartPlexContentCacher()
{
OmbiQuartz.Scheduler.TriggerJob(new JobKey(nameof(IPlexContentSync) +
"Trigger"), new JobDataMap(new Dictionary<string, string> { { "recentlyAddedSearch", "false" } }));
OmbiQuartz.Scheduler.TriggerJob(new JobKey(nameof(IPlexContentSync), "Plex"), new JobDataMap(new Dictionary<string, string> { { "recentlyAddedSearch", "false" } }));
return true;
}
@ -121,7 +120,7 @@ namespace Ombi.Controllers
[HttpPost("plexrecentlyadded")]
public bool StartRecentlyAdded()
{
OmbiQuartz.Scheduler.TriggerJob(new JobKey(nameof(PlexContentSync)), new JobDataMap(new Dictionary<string, string> { { "recentlyAddedSearch", "true" } }));
OmbiQuartz.Scheduler.TriggerJob(new JobKey(nameof(IPlexContentSync), "Plex"), new JobDataMap(new Dictionary<string, string> { { "recentlyAddedSearch", "true" } }));
return true;
}
@ -132,7 +131,7 @@ namespace Ombi.Controllers
[HttpPost("embycontentcacher")]
public async Task<bool> StartEmbyContentCacher()
{
await OmbiQuartz.TriggerJob(nameof(IEmbyContentSync));
await OmbiQuartz.TriggerJob(nameof(IEmbyContentSync), "Emby");
return true;
}
@ -143,7 +142,7 @@ namespace Ombi.Controllers
[HttpPost("newsletter")]
public async Task<bool> StartNewsletter()
{
await OmbiQuartz.TriggerJob(nameof(INewsletterJob));
await OmbiQuartz.TriggerJob(nameof(INewsletterJob), "Emby");
return true;
}
}

@ -386,7 +386,7 @@ namespace Ombi.Controllers
_cache.Remove(CacheKeys.RadarrRootProfiles);
_cache.Remove(CacheKeys.RadarrQualityProfiles);
await OmbiQuartz.TriggerJob(nameof(IRadarrSync));
await OmbiQuartz.TriggerJob(nameof(IRadarrSync), "DVR");
}
return result;
}

Loading…
Cancel
Save