scheduler
This commit is contained in:
44
EnvelopeGenerator.Web/Scheduler.cs
Normal file
44
EnvelopeGenerator.Web/Scheduler.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using DigitalData.Modules.Base;
|
||||
using DigitalData.Modules.Logging;
|
||||
using EnvelopeGenerator.Common;
|
||||
using Quartz;
|
||||
using System;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace EnvelopeGenerator.Web
|
||||
{
|
||||
public class Scheduler : BaseClass
|
||||
{
|
||||
private const string DATABASE = "DATABASE";
|
||||
private const string LOGCONFIG = "LOGCONFIG";
|
||||
|
||||
private string ConnectionString;
|
||||
|
||||
public Scheduler(LogConfig logConfig, string connectionString) : base(logConfig)
|
||||
{
|
||||
this.ConnectionString = connectionString;
|
||||
}
|
||||
|
||||
public void ScheduleJob<TJob>(IServiceCollectionQuartzConfigurator q, string name, int interval) where TJob : IJob
|
||||
{
|
||||
var jobKey = new JobKey(name);
|
||||
var jobData = new JobDataMap
|
||||
{
|
||||
{ DATABASE, ConnectionString },
|
||||
{ LOGCONFIG, LogConfig }
|
||||
};
|
||||
|
||||
q.AddJob<TJob>(opts => opts
|
||||
.WithIdentity(jobKey)
|
||||
.UsingJobData(jobData));
|
||||
|
||||
q.AddTrigger(opts => opts
|
||||
.ForJob(jobKey)
|
||||
.WithIdentity($"{name}-trigger")
|
||||
.WithSimpleSchedule(s => s
|
||||
.RepeatForever()
|
||||
.WithIntervalInMinutes(interval)));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user