45 lines
1.3 KiB
C#
45 lines
1.3 KiB
C#
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)));
|
|
}
|
|
}
|
|
}
|