mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-08-14 02:26:55 -07:00
Fixed the notifications issue
This commit is contained in:
parent
96e3e88261
commit
181bd53202
22 changed files with 210 additions and 177 deletions
8
src/Ombi.Helpers/JobDataKeys.cs
Normal file
8
src/Ombi.Helpers/JobDataKeys.cs
Normal file
|
@ -0,0 +1,8 @@
|
|||
namespace Ombi.Helpers
|
||||
{
|
||||
public class JobDataKeys
|
||||
{
|
||||
public const string RecentlyAddedSearch = "recentlyAddedSearch";
|
||||
public const string NotificationOptions = nameof(NotificationOptions);
|
||||
}
|
||||
}
|
|
@ -14,6 +14,7 @@
|
|||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.2.0" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
|
||||
<PackageReference Include="Nito.AsyncEx" Version="5.0.0-pre-05" />
|
||||
<PackageReference Include="Quartz" Version="3.0.7" />
|
||||
<PackageReference Include="System.Security.Claims" Version="4.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
91
src/Ombi.Helpers/OmbiQuartz.cs
Normal file
91
src/Ombi.Helpers/OmbiQuartz.cs
Normal file
|
@ -0,0 +1,91 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Quartz;
|
||||
using Quartz.Impl;
|
||||
using Quartz.Spi;
|
||||
|
||||
namespace Ombi.Helpers
|
||||
{
|
||||
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(new JobKey(name, group));
|
||||
if (jobData != null)
|
||||
{
|
||||
foreach (var o in jobData)
|
||||
{
|
||||
jobBuilder.UsingJobData(o.Key, o.Value);
|
||||
}
|
||||
}
|
||||
|
||||
if(!cronExpression.HasValue())
|
||||
{
|
||||
jobBuilder.StoreDurably(true);
|
||||
}
|
||||
|
||||
var job = jobBuilder.Build();
|
||||
if (cronExpression.HasValue())
|
||||
{
|
||||
ITrigger jobTrigger = TriggerBuilder.Create()
|
||||
.WithIdentity(name + "Trigger", group)
|
||||
.WithCronSchedule(cronExpression,
|
||||
x => x.WithMisfireHandlingInstructionFireAndProceed())
|
||||
.ForJob(name, group)
|
||||
.StartNow()
|
||||
.Build();
|
||||
await Scheduler.ScheduleJob(job, jobTrigger);
|
||||
}
|
||||
else
|
||||
{
|
||||
await Scheduler.AddJob(job, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static async Task TriggerJob(string jobName, string group)
|
||||
{
|
||||
await Scheduler.TriggerJob(new JobKey(jobName, group));
|
||||
}
|
||||
|
||||
public static async Task TriggerJob(string jobName, string group, IDictionary<string, object> data)
|
||||
{
|
||||
await Scheduler.TriggerJob(new JobKey(jobName, group), new JobDataMap(data));
|
||||
}
|
||||
|
||||
public static async Task Start()
|
||||
{
|
||||
await Scheduler.Start();
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue